You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Here we also have to specify our relations, just like in eager loading. The only difference is that we are required to use an `Entity` for our `$returnType`. That's because the entity will be responsible for triggering the relation request.
91
94
92
95
```php
96
+
use Michalsn\CodeIgniterNestedModel\Relation;
97
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
98
+
93
99
class UserModel extends Model
94
100
{
95
101
use HasRelations;
@@ -115,6 +121,8 @@ class UserModel extends Model
115
121
The entity class we use have to use `hasLazyRelations` trait.
116
122
117
123
```php
124
+
use Michalsn\CodeIgniterNestedModel\Traits\HasLazyRelations;
Copy file name to clipboardExpand all lines: docs/relations.md
+24
Original file line number
Diff line number
Diff line change
@@ -17,6 +17,9 @@ A one-to-one relationship where one model is associated with exactly one instanc
17
17
A User model has one Profile. Each user can have only one profile.
18
18
19
19
```php
20
+
use Michalsn\CodeIgniterNestedModel\Relation;
21
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
22
+
20
23
class UserModel extends Model
21
24
{
22
25
use HasRelations;
@@ -50,6 +53,9 @@ A one-to-many relationship where one model is associated with multiple instances
50
53
A User has many Posts. Each user can have multiple posts.
51
54
52
55
```php
56
+
use Michalsn\CodeIgniterNestedModel\Relation;
57
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
58
+
53
59
class UserModel extends Model
54
60
{
55
61
use HasRelations;
@@ -83,6 +89,9 @@ A one-to-many inverse relationship where a model belongs to another model.
83
89
A Post belongs to a User. Each profile is associated with one specific user.
84
90
85
91
```php
92
+
use Michalsn\CodeIgniterNestedModel\Relation;
93
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
94
+
86
95
class PostModel extends Model
87
96
{
88
97
use HasRelations;
@@ -116,6 +125,9 @@ A specialized type of one-to-one relationship where a parent model has multiple
116
125
This type of relation is especially useful for scenarios where a model has many records, but you only need to retrieve one representative record from the set.
117
126
118
127
```php
128
+
use Michalsn\CodeIgniterNestedModel\Relation;
129
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
130
+
119
131
class UserModel extends Model
120
132
{
121
133
use HasRelations;
@@ -175,6 +187,9 @@ Consider an application where:
175
187
You want to retrieve a User's Address without needing to manually query through the Company.
176
188
177
189
```php
190
+
use Michalsn\CodeIgniterNestedModel\Relation;
191
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
192
+
178
193
class UserModel extends Model
179
194
{
180
195
use HasRelations;
@@ -225,6 +240,9 @@ Consider an application where::
225
240
You want to fetch all Posts for a Country, even though the Posts table does not directly reference the Country.
226
241
227
242
```php
243
+
use Michalsn\CodeIgniterNestedModel\Relation;
244
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
245
+
228
246
class CountryModel extends Model
229
247
{
230
248
use HasRelations;
@@ -267,6 +285,9 @@ The pivot table should have a name derived from the name of both tables. In this
267
285
The table should contain a primary key (`id` - auto_increment) and two foreign keys for both of models: `course_id` and `student_id`.
268
286
269
287
```php
288
+
use Michalsn\CodeIgniterNestedModel\Relation;
289
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
290
+
270
291
class StudentModel extends Model
271
292
{
272
293
use HasRelations;
@@ -285,6 +306,9 @@ class StudentModel extends Model
285
306
}
286
307
```
287
308
```php
309
+
use Michalsn\CodeIgniterNestedModel\Relation;
310
+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
0 commit comments