Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
order_by related model's field first
  • Hi all,

    How can I specify the order of 'order by' conditions including related fields?
    Here is my code:

    $results = Model_Article::query()
                    ->related('author')
                    ->order_by(
                                   array(
                                       'author.name'=>'ASC',
                                       'category_id'=>'ASC',
                                   )
                    )
                    ->get();
            

    I want to sort by author name first and then category_id. But the above code results the SQL like:
    "ORDER BY `t0`.`category_id` ASC, `t1`.`name` ASC".

    Is there any way to make the related table's field come before the main table's?
  • What version of FuelPHP are you on?

    This issue was reported (https://github.com/fuel/orm/issues/134) and fixed about 2 months ago.
  • You're right! Mine was 1.2. I should have checked on the latest version first.
    Thanks!

Howdy, Stranger!

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

In this Discussion