staudenmeir / eloquent-has-many-deep

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

HasOneTrhough MorphOne #210

Closed plakhin closed 1 year ago

plakhin commented 1 year ago

Hello! What would be the right way to set the relationship? Can't figure out :(

I have this table structure:

Owners
    - id

Cars
    - id
    - owner_id

Keys
    - id
    - keyable_type
    - keyable_id

I already have this relationships set and working: Owner > hasOne > Car Car > morphOne > Key Key > morphTo > Car Car > belongsTo > Owner (Owner > hasOne > Car > morphOne > Key) (Key > morphTo > Car > belongsTo > Owner)

What should I use to get this relationship? Owner > ??? > Key And inverse: Key > ??? > Owner

Will highly appreciate your help 🙏

plakhin commented 1 year ago

hasOneDeepFromRelations() helped a lot, finally set both with just hasOneDeep()