Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Can I Use \DB::expr() IN ORM Query?
  • Hello.
    I Hope To Write SQL Like This:
    -------------------------------------------
    SELECT DATE_FORMAT(created_at, '%Y-%m-%d') AS date, COUNT(*) 
    FROM tbl_xxx
    GROUP BY (DATE_FORMAT(created_at, '%Y-%m-%d'));
    -------------------------------------------

    Can I Build By ORM Query?
    I Tried, But Not Work...

    One, It's Seems Way To Most Simple Is Using "\DB::expr()", But Not Work.
    Next, I Passed Subquery To "->select()" method, But...Oh...
     
  • HarroHarro
    Accepted Answer
    DB::expr() can not be used with ORM queries in a select(), only in where().

    The ORM is not a query builder, use a normal DB. ORM can't produce that group_by either, and because the result doesn't include the primary key, it will also not be able to hydrate the result back into ORM objects.
  • I understand, thanks you.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion