Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Parent's $with relations are applied on all it's embedsMany relationships #2168

Unanswered
Al-bambino asked this question in Q&A
Discussion options

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
]
You must be logged in to vote

Replies: 0 comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant
Converted from issue

This discussion was converted from issue #2168 on December 26, 2020 07:19.

AltStyle によって変換されたページ (->オリジナル) /