eloquent-has-many-deep icon indicating copy to clipboard operation
eloquent-has-many-deep copied to clipboard

Support multiple keys

Open aakarim opened this issue 4 years ago • 2 comments

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?

aakarim avatar Oct 22 '20 11:10 aakarim

I'll look into it.

staudenmeir avatar Oct 25 '20 13:10 staudenmeir

@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.

achatzi78 avatar Jun 23 '22 10:06 achatzi78

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

staudenmeir avatar Aug 27 '22 07:08 staudenmeir

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

achatzi78 avatar Aug 27 '22 07:08 achatzi78