Skip to content

hasMany relationts not working on subdocuments #1817

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
luismabenitez opened this issue Aug 30, 2019 · 2 comments
Closed

hasMany relationts not working on subdocuments #1817

luismabenitez opened this issue Aug 30, 2019 · 2 comments

Comments

@luismabenitez
Copy link

I'm not sure this part is working properly.

Just trying to do some relationship but I'm getting a null on my requests.

I have a "passengers" collection with a trip_id. Something like this:

{  
   "_id":"5d680fd36882d19e782d67bd",
   "trip_id":"5d680fcb6882d19e782d6380",
   "name":"Lee Jones"
}

And a collection with the name "lotes" that contain documents that each one has many trips. Something like this:

{  
   "_id":"5d680fca6882d19e782d60f6",
   "user_id":"5d680fca6882d19e782d60b4",
   "date_to_ride":"2019-08-29T22:00:00.000+00:00",
   "trips":[  
      {  
         "trip_id":"5d680fcb6882d19e782d6380",
         "car":"VW Golf"
      }
   ]
}

So I want to get all passengers that has same trip_id when I'm getting the trip info.

This is my relation on the Trip model:

public function passengers()
{
    return $this->hasMany(\App\Passenger::class, 'trip_id', 'trips.trip_id')->whereNotNull('trip_id');
}

My result? "passengers": []

@Smolevich
Copy link
Contributor

You can join to slack community and ask there

@Smolevich
Copy link
Contributor

And describe full code for eloquent models

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants