OfMany and pivot data #39638
Unanswered
chris-ware
asked this question in
General
Replies: 0 comments
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.
-
Not sure if this is an idea, or a bug, or me simply missing something. The OfMany set of functions (oldestOfMany, latestOfMany and OfMany itself) are really useful for returning a single model as part of a relationship, however, this concept does connect to many-to-many relationships via a pivot table. With a standard relationship, you can instruct the relationship to load pivot data, as well as use pivot data as part of the relationship, however if you utilise a OfMany, it seems you cannot interact with pivot data. Take the following code as example:
In this example, we return a collection of assets, but in more instances than not, we actually are only expecting a single asset. This currently means that we need to check for the fact a collection has been returned and then run first() on it. In an ideal world, the OfMany mechanic would allow for the above behaviour of interacting with pivot data.
I will admit that as much as I'd love to do a PR for this, the required behaviour is far beyond my knowledge as a developer.
Beta Was this translation helpful? Give feedback.
All reactions