2

I've collections: users, organisations, emails. A user can have 1..* emails. Even so an organisation can have 1..* emails.

Without linking tables (that's the NoSQL principe), these are my collections:

User Collection:

[{'_id': ObjectId("54feabdae75a4f4168b7acd9"), 'name': 'Henri', 'emails': [{'_id': '54feabdae75a4f4168b7acda'}] }]

Organisation Collection:

[{'_id': ObjectId("54feabdae75a4f4168be24a4"), 'name': 'MyOrg.org', 'emails': [{'_id': '54feabdae75a4f4168b7acda'}] }]

Email Collection:

[{ "_id" : ObjectId("54feabdae75a4f4168b7acda"), "email" : "henriabc@gmail.com" }]

My relationships from "user" Model and "organisation" Model:

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

Call to eager load:

public fullUser($id) {
    return User::find($id)->with('emails')->get();
}

But how to (eager) load an user with his emails? Method above doesn't populate emails.

eduardo a
  • 152
  • 4
  • 17
schellingerht
  • 5,726
  • 2
  • 28
  • 56

1 Answers1

0

use this:

public fullUser($id) {
    $user = User::find($id);
    $user->emails();
    return $user();
}