3

Let's say there is a User model that embedsMany House models.

public function houses()
    {
        return $this->embedsMany('App\House');
    }

Is there a way to directly retrieve a list of all houses for all users, without first retrieving all users and then iterating through each users embedded houses?

Passing $houses = House::all(); to the view, returns nothing.

4

1 回答 1

2

Short answer: no.

For what I know there is no way to select embedded documents in Mongo without retrieving the owner.

Embedded models are inside other models they do not have his own collection (table).

If you need to retrieve them separately probably you need to define House with his own collection (table) and not as embedded.

于 2017-03-04T14:26:30.130 回答