staudenmeir / eloquent-has-many-deep

Laravel Eloquent HasManyThrough relationships with unlimited levels
MIT License
2.67k stars 157 forks source link

Support multiple keys #105

Closed aakarim closed 2 years ago

aakarim commented 4 years ago

Hi, very useful package, thank you.

I am trying to use a hasManyDeep with multiple keys. This means that there are two (or more) keys on the foreign table that I want to match to.

SpecialPersonList -> SpecialPerson -> Profile -> User

I want to get all the Users in this SpecialPersonList.

However, the SpecialPerson->Profile relationship is a hasMany relationship with multiple keys either fb_id or twitter_id. If I want to go from SpecialPerson->Profile I can use this package https://github.com/topclaudy/compoships which allows me to get there. Unfortunately, I can't use hasManyDeep with this package (it doesn't support the multiple keys relation). Are there any changes I/we can make to support either a) multiple keys or b) the Compoships package?

staudenmeir commented 4 years ago

I'll look into it.

achatzi78 commented 2 years ago

@staudenmeir I know this is old, but I came across the same issue. I also use the Compoships package and tried it with yours but it did not work.

I hope you find the time to implement something like this.

Thanks for a great package.

staudenmeir commented 2 years ago

I released v1.16 (Laravel 9) with support for composite keys.

If you concatenate existing relationships with hasManyDeepFromRelations(), you can now include compoships relationships: https://github.com/staudenmeir/eloquent-has-many-deep#third-party-packages

If you define relationships manually with hasManyDeep(), you can now use the CompositeKey class: https://github.com/staudenmeir/eloquent-has-many-deep#composite-keys

achatzi78 commented 2 years ago

@staudenmeir Great news! Thank you for this, it will surely come in handy in my current project.