You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the solution you'd like
Sometimes it is necessary to use an alias in a JOIN - when you want to make two separate table joins to the same column for example. Active Record does not support this, nor does it support the addition of aribtrary SQL to a query it is building, so currently you cannot (for example) use a lookup table multiple times in the same request. For example (from the MySQL docs you might want to do this
SELECT t1.name, t2.salary
FROM employee AS t1 INNER JOIN info AS t2 ON t1.name = t2.name;
Currently this is not possible to specify using Active Record' join() method.
It would be good to add the ability to specify an alias in the join() method.
It would be easy enough to add to the function by defining a further optional parameter to those already in place, but it would be the necessary to disable the application of the _protect_identifiers() method to the join condition, since otherwise AR would attempt to (at the very least) prefix the alias prefix (similar to the effect of setting $escape = false in a select() statement).
Describe alternatives you've considered
Usually the need for aliased joins can be avoided by data table design (e.g. avoiding the need for look-ups by duplicating data), but if you are working with legacy data this might not be possible.
Teachability, Documentation, Adoption, Migration Strategy
A small addition would be needed to the AR documentation to note the additional parameter, and that table-name protection is removed when an alias specified.
I am capable and would like to work on implementation of this feature if it is considered.
The text was updated successfully, but these errors were encountered:
Describe the solution you'd like
Sometimes it is necessary to use an alias in a JOIN - when you want to make two separate table joins to the same column for example. Active Record does not support this, nor does it support the addition of aribtrary SQL to a query it is building, so currently you cannot (for example) use a lookup table multiple times in the same request. For example (from the MySQL docs you might want to do this
Currently this is not possible to specify using Active Record' join() method.
It would be good to add the ability to specify an alias in the join() method.
It would be easy enough to add to the function by defining a further optional parameter to those already in place, but it would be the necessary to disable the application of the
_protect_identifiers()
method to the join condition, since otherwise AR would attempt to (at the very least) prefix the alias prefix (similar to the effect of setting$escape = false
in a select() statement).Describe alternatives you've considered
Usually the need for aliased joins can be avoided by data table design (e.g. avoiding the need for look-ups by duplicating data), but if you are working with legacy data this might not be possible.
Teachability, Documentation, Adoption, Migration Strategy
A small addition would be needed to the AR documentation to note the additional parameter, and that table-name protection is removed when an alias specified.
The text was updated successfully, but these errors were encountered: