Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
How to order related data
  • Hi guys, I've a question regarding ORM. I have 2 tables:
    - contents
    - categories

    Both have a "many to many" relation with each other, so for example when I perform "Model_Categories::find(1)", I can access all contents associated with category 1.

    There exists a way to order the contents by another field instead of using "id"? Or I have to reorder them by myself?
    Because I want to order them usind another field (updated_at).

  • HarroHarro
    Accepted Answer
    If you always want that specific order, you can define that in the relation definition. If you want it only for this specific query, specify it on the query:

    Model_Categories::find(1, array('related' => array('contents'), 'order_by' => array('contents.fieldname' => 'ASC')))

    (you make have to check the correct syntax, I never use this array notation).
  • It worked, thanks Harro!

Howdy, Stranger!

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

In this Discussion