Love Fuel?
Donate
About
Forums
Discussions
Login
FuelPHP Forums
Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Orm
Sorting + 0
richtestani
February 2013
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
Harro
February 2013
You can pass anything as-is to DB by encapsulating whatever you want to pass using DB::expr().
richtestani
February 2013
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.
Harro
February 2013
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.
richtestani
February 2013
Thank, I rewrote my query and your comments got me the output I needed.
Rich
Add a Comment
Howdy, Stranger!
It looks like you're new here. If you want to get involved, click one of these buttons!
Sign In
Apply for Membership
Categories
All Discussions
5,088
General
↳ General
3,364
↳ Job Board
13
↳ Installation & Setup
214
Packages
↳ Oil
213
↳ Orm
700
↳ Auth
260
Development
↳ Tips and Tutorials
126
↳ Code share
145
↳ Applications
52
In this Discussion
Harro
February 2013
richtestani
February 2013