I'm trying to order by and group by tag
$result = Model_Tag::query()->select(\Fuel\Core\Db::expr('count(*)'),'count')->select('tag')->group_by('tag')->order_by('count','desc')->get();
$result = Model_Tag::query()->select(\Fuel\Core\Db::expr('count(*)','count'))->select('tag')->group_by('tag')->order_by('count','desc')->get();
However, no matter what I do I get the error that the count is not defined as ORM insists on aliasing the field name:
SELECT count(*) AS
t0_c0
,t0
.tag
ASt0_c1
,t0
.id
ASt0_c2
FROMtag
ASt0
GROUP BYt0
.tag
ORDER BYt0
.count
DESC"
Resulting in a column not found error
Alternatively:
$query = Model_Tag::query()->select(\Fuel\Core\Db::expr('count(*) as count'))->select('tag')->group_by('tag')->order_by('count','desc')->get();
query
SELECT count(*) as count AS
t0_c0
,t0
.tag
ASt0_c1
,t0
.id
ASt0_c2
FROMtag
ASt0
GROUP BYt0
.tag
ORDER BYt0
.count
DESC
gives a syntax error