Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Sorting + 0
  • I have a column with a varchar type, which is mostly numbers with a letter extension (41t for example).

    Ordering this fields doesn't really do anything, but with SQL you can add a 0 to sort it with numbers.

    ORDER BY `field`+0

    In fuel, we supply a name within an array.
    Is there a way to sort this properly within fuel's API or do I need to write custom SQL?

    Thanks
    Rich
  • You can pass anything as-is to DB by encapsulating whatever you want to pass using DB::expr().
  • So how would I encapsulate it in this example?


    Model_Cards::find('all', array(
    'order_by' => array(
    'number' => 'asc'
    ),
    'related' => array('sets'=>array(
    'where'=>array(
    array('year', $this->year),
    array('manufacturer_id', $manufacturer->id),
    array('genre_id', $genre->id),
    array('slug', 'like', "%$this->set%")
    )
    )
    ),
    ));


    There is no code button in this editor.


  • HarroHarro
    Accepted Answer
    Don't think you can't, as the order_by fieldname in this syntax is an array key.
    I never use find(), I prefer method chaining.
  • Thank, I rewrote my query and your comments got me the output I needed.
    Rich

Howdy, Stranger!

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

In this Discussion