latestOfMany(), oldestOfMany(), ofMany() $relation parameter #38580
Unanswered
Martleby
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
It isn't mentioned in the docs (AFAIK), but each of latestOfMany(), oldestOfMany() ,and ofMany() support a final parameter $relation.
This is extremely useful if you ever need to specify the alias of the correlated subqueries Eloquent generates because of name conflicts and so on.
For instance, my setup is a bit complicated because I integrate a third party SQL Server db in my application. The db doesn't follow Laravel naming conventions - all the tables are CamelCased, as are fields, table names are generally not plural etc. This caused the default name Eloquent generated for the correlated ofMany subquery to pick the same name as the base table, causing an error. By specifying the $relation this solved the problem.
Just thought I'd share this as it is so useful - I wonder why it isn't mentioned in the docs?
Cheers,
Martin.
Beta Was this translation helpful? Give feedback.
All reactions