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
@@ -805,19 +805,23 @@ class User extends Model
805
805
}
806
806
}
807
807
```
808
+
**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.
808
809
809
810
### EmbedsMany Relationship
810
811
811
812
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.
812
813
813
814
**REMEMBER**: These relations return Eloquent collections, they don't return query builder objects!
814
815
816
+
**Breaking changes** starting from v4.0 you need to define the return type of EmbedsOne and EmbedsMany relation for it to work
817
+
815
818
```php
816
819
use MongoDB\Laravel\Eloquent\Model;
820
+
use MongoDB\Laravel\Relations\EmbedsMany;
817
821
818
822
class User extends Model
819
823
{
820
-
public function books()
824
+
public function books(): EmbedsMany
821
825
{
822
826
return $this->embedsMany(Book::class);
823
827
}
@@ -886,10 +890,11 @@ Like other relations, embedsMany assumes the local key of the relationship based
Copy file name to clipboardExpand all lines: src/Eloquent/HybridRelations.php
+4
Original file line number
Diff line number
Diff line change
@@ -272,6 +272,10 @@ public function belongsToMany(
272
272
273
273
$instance = new$related;
274
274
275
+
if ($relatedPivotKey === $relation) {
276
+
thrownew \LogicException(sprintf('In %s::%s(), the key cannot be identical to the relation name "%s". The default key is "%s".', static::class, $relation, $relation, $instance->getForeignKey().'s'));
0 commit comments