-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Parent's $with relations are applied on all it's embedsMany relationships #2168
Unanswered
Al-bambino
asked this question in
Q&A
-
When Model has a field $with
set, these relations are being applied to all models that are in embedsMany
relation with that model.
class User extends MongoModel { protected $with = ['someOtherRelaton', 'anotherRelation' ]; // ... public function comments() { return $this->embedsMany(Comment::class, 'comments'); } }
Now, when you query Users
you'll get someOtherRelation
and anotherRelation
as fields in comments
.
$comment = $user->comments->first(); dd($comment->toArray());
Will generate you:
array:4 [ "your_filed" => "your field", //... "someOtherRelaton" => null, "anotherRelation" => null ]
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment