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-3
Original file line number
Diff line number
Diff line change
@@ -856,19 +856,23 @@ class User extends Model
856
856
}
857
857
}
858
858
```
859
+
**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.
859
860
860
861
### EmbedsMany Relationship
861
862
862
863
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.
863
864
864
865
**REMEMBER**: These relations return Eloquent collections, they don't return query builder objects!
865
866
867
+
**Breaking changes** starting from v4.0 you need to define the return type of EmbedsOne and EmbedsMany relation for it to work
868
+
866
869
```php
867
870
use Jenssegers\Mongodb\Eloquent\Model;
871
+
use Jenssegers\Mongodb\Relations\EmbedsMany;
868
872
869
873
class User extends Model
870
874
{
871
-
public function books()
875
+
public function books(): EmbedsMany
872
876
{
873
877
return $this->embedsMany(Book::class);
874
878
}
@@ -937,10 +941,11 @@ Like other relations, embedsMany assumes the local key of the relationship based
0 commit comments