orm icon indicating copy to clipboard operation
orm copied to clipboard

Cannot reliably use DB::expr within ORM query + related due to table/column aliasing

Open torchedmedia opened this issue 12 years ago • 4 comments

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.

torchedmedia avatar Jan 24 '13 23:01 torchedmedia

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.

emlynwest avatar Apr 14 '13 21:04 emlynwest

This might now be fixed with https://github.com/fuel/core/pull/1727

emlynwest avatar Jul 09 '14 12:07 emlynwest

Ah sorry, not the issue I was thinking of, ignore that.

emlynwest avatar Jul 09 '14 12:07 emlynwest

+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);

ve3 avatar Jan 06 '15 09:01 ve3