Skip to content

Commit acbe29a

Browse files
authored
docs: add imports to the examples (#8)
1 parent fa96be9 commit acbe29a

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

docs/basic_usage.md

+8
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
First, we have to define our relations. In the below example we will have `UserModel`, which have one-to-one relation with `ProfileModel`.
99

1010
```php
11+
use Michalsn\CodeIgniterNestedModel\Relation;
12+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
13+
1114
class UserModel extends Model
1215
{
1316
use HasRelations;
@@ -90,6 +93,9 @@ $userModel->with('profile')->save($user);
9093
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.
9194

9295
```php
96+
use Michalsn\CodeIgniterNestedModel\Relation;
97+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
98+
9399
class UserModel extends Model
94100
{
95101
use HasRelations;
@@ -115,6 +121,8 @@ class UserModel extends Model
115121
The entity class we use have to use `hasLazyRelations` trait.
116122

117123
```php
124+
use Michalsn\CodeIgniterNestedModel\Traits\HasLazyRelations;
125+
118126
class User extends Entity
119127
{
120128
use HasLazyRelations;

docs/relations.md

+24
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ A one-to-one relationship where one model is associated with exactly one instanc
1717
A User model has one Profile. Each user can have only one profile.
1818

1919
```php
20+
use Michalsn\CodeIgniterNestedModel\Relation;
21+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
22+
2023
class UserModel extends Model
2124
{
2225
use HasRelations;
@@ -50,6 +53,9 @@ A one-to-many relationship where one model is associated with multiple instances
5053
A User has many Posts. Each user can have multiple posts.
5154

5255
```php
56+
use Michalsn\CodeIgniterNestedModel\Relation;
57+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
58+
5359
class UserModel extends Model
5460
{
5561
use HasRelations;
@@ -83,6 +89,9 @@ A one-to-many inverse relationship where a model belongs to another model.
8389
A Post belongs to a User. Each profile is associated with one specific user.
8490

8591
```php
92+
use Michalsn\CodeIgniterNestedModel\Relation;
93+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
94+
8695
class PostModel extends Model
8796
{
8897
use HasRelations;
@@ -116,6 +125,9 @@ A specialized type of one-to-one relationship where a parent model has multiple
116125
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.
117126

118127
```php
128+
use Michalsn\CodeIgniterNestedModel\Relation;
129+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
130+
119131
class UserModel extends Model
120132
{
121133
use HasRelations;
@@ -175,6 +187,9 @@ Consider an application where:
175187
You want to retrieve a User's Address without needing to manually query through the Company.
176188

177189
```php
190+
use Michalsn\CodeIgniterNestedModel\Relation;
191+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
192+
178193
class UserModel extends Model
179194
{
180195
use HasRelations;
@@ -225,6 +240,9 @@ Consider an application where::
225240
You want to fetch all Posts for a Country, even though the Posts table does not directly reference the Country.
226241

227242
```php
243+
use Michalsn\CodeIgniterNestedModel\Relation;
244+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
245+
228246
class CountryModel extends Model
229247
{
230248
use HasRelations;
@@ -267,6 +285,9 @@ The pivot table should have a name derived from the name of both tables. In this
267285
The table should contain a primary key (`id` - auto_increment) and two foreign keys for both of models: `course_id` and `student_id`.
268286

269287
```php
288+
use Michalsn\CodeIgniterNestedModel\Relation;
289+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
290+
270291
class StudentModel extends Model
271292
{
272293
use HasRelations;
@@ -285,6 +306,9 @@ class StudentModel extends Model
285306
}
286307
```
287308
```php
309+
use Michalsn\CodeIgniterNestedModel\Relation;
310+
use Michalsn\CodeIgniterNestedModel\Traits\HasRelations;
311+
288312
class CourseModel extends Model
289313
{
290314
use HasRelations;

0 commit comments

Comments
 (0)