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
Copy file name to clipboardExpand all lines: README.md
+11-3Lines changed: 11 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -853,19 +853,23 @@ class User extends Model
853
853
}
854
854
}
855
855
```
856
+
**Warning:** naming the foreign key same as the relation name will prevent the relation for being called on dynamic property, i.e. in the example above if you replaced `group_ids` with `groups` calling `$user->groups` will return the column instead of the relation.
856
857
857
858
### EmbedsMany Relationship
858
859
859
860
If you want to embed models, rather than referencing them, you can use the `embedsMany` relation. This relation is similar to the `hasMany` relation but embeds the models inside the parent object.
860
861
861
862
**REMEMBER**: These relations return Eloquent collections, they don't return query builder objects!
862
863
864
+
**Breaking changes** starting from v4.0 you need to define the return type of EmbedsOne and EmbedsMany relation for it to work
865
+
863
866
```php
864
867
use MongoDB\Laravel\Eloquent\Model;
868
+
use MongoDB\Laravel\Relations\EmbedsMany;
865
869
866
870
class User extends Model
867
871
{
868
-
public function books()
872
+
public function books(): EmbedsMany
869
873
{
870
874
return $this->embedsMany(Book::class);
871
875
}
@@ -934,10 +938,11 @@ Like other relations, embedsMany assumes the local key of the relationship based
0 commit comments