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.tagASt0_c1,t0.idASt0_c2FROMtagASt0GROUP BYt0.tagORDER BYt0.countDESC"
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.tagASt0_c1,t0.idASt0_c2FROMtagASt0GROUP BYt0.tagORDER BYt0.countDESC
gives a syntax error
In FuelPHP Version 1.8, access you controller and you query set this example:
if you get the count
Warning! Do not call your
select('tag')because you are already usingModel_TagRef: https://fuelphp.com/docs/classes/database/usage.html