Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Order_By Not Working in a Task
  • I have an order_by statement on a relationship in an ORM query:

    $vehicles = \Model_Inventory_Main::find('all', array(
    'related' => array(
    'photos' => array(
    'order_by' => array('order' => 'ASC'),
    'where' => array(
    array('type', '!=', 'new')

    Now, the problem is that it's not ordering the relation by the 'order' column. It's ordering them by the primary key.

    This is nuts though, because I copy/paste the query into a controller and run it and it sorts them properly. Any ideas?

  • Odd, there is no difference between a task and a controller. So I'm clueless...
  • That's where I'm at right now too.
    Wasn't sure how it made sense at all.. guess I will try and find an alternate way to do this or just write the query by hand.

    Looks like the query itself might be working.. strange as F.
  • HarroHarro
    Accepted Answer
    Since it's a join, I assume you want them ordered on photo.order PER inventory item? If so, you need to add an order on inventory id too, otherwise it will order all order == 1's, regardless of the inventory item...
  • I removed the order_by there, and moved it to the model (since I always want photos ordered by model). Works great now. No idea why it worked one place and not the other - chalk it up to a fluke.

Howdy, Stranger!

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

In this Discussion