HasManyThrough with pivot support #52763
Unanswered
isaiahfisher
asked this question in
Ideas
Replies: 1 comment
-
There is a package hasManyDeep that may support this. https://github.com/staudenmeir/eloquent-has-many-deep Interesting how you have box-box_item-item_error as 1:many and box-box_item-pivot-item_error as 1:many. You will need a relation defined for each combination. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Recently, I wanted to define a structure where we have 3 tables (4 with pivot):
boxes - id
box_items - id, box_id
item_errors - id, box_item_id, error_code
(pivot) box_items_item_errors - id, box_item_id, item_error_id
My goal was to get all of the unique error codes associated with a specific box, so I wanted to use HasManyThrough to go from
box -> box_items -> item_errors.
Unfortunately, due to the ManyToMany relationship between box_items and item_errors this did not work.
Instead now I am forced to iterate over the collection in php to get distinct values and flatten the results into an array.
It would be great if we could support ManyToMany relationships in HasManyThrough so that this can be accomplished at the database level for more performance.
Beta Was this translation helpful? Give feedback.
All reactions