Cannot reliably use DB::expr within ORM query + related due to table/column aliasing
I have an ORM query for a related object ("base"), which looks like this: $class::query()->related('base');
I want to add a condition in the query like so: ->where(\DB::expr('DATE(base.created)'), $date_variable), but because of the column and table aliasing in ORM, neither base nor created are recognized.
Ideally there would be a way to translate "base" and "created" into their aliases by using some method on the query object. Is this possible? If not, can it be added?
Thanks.
The problem with this is that the aliases are generated when the sql is compiled, and if that query is created through the ORM the DB class does not have any knowledge of how relation names map to aliases.
This might now be fixed with https://github.com/fuel/core/pull/1727
Ah sorry, not the issue I was thinking of, ignore that.
+1 To this issue. I want it too. I cannot do $query->where(\DB::expr('DATE(apm_meters.meter_daily_date)'), '<=', $filter_bill_cycle_date);