I need something like this:
$products = Products::getTable()->find(274);
foreach ($products->Categories->orderBy('title') as $category)
{
echo "{$category->title}<br />";
}
I know is it not possible, but... How can I do something like this without creating a Doctrine_Query?
Thanks.
You can also do:
$this->hasMany('Category as Categories', array(...
'orderBy' => 'title ASC'));
In your schema file it looks like:
Relations:
Categories:
class: Category
....
orderBy: title ASC
I was just looking at the same problem. You need to convert the Doctrine_Collection into an array:
$someDbObject = Doctrine_Query::create()...;
$children = $someDbObject->Children;
$children = $children->getData(); // convert from Doctrine_Collection to array
Then you can create a custom sort function and call it:
// sort children
usort($children, array(__CLASS__, 'compareChildren')); // fixed __CLASS__
Where compareChildren looks something like:
private static function compareChildren($a, $b) {
// in this case "label" is the name of the database column
return strcmp($a->label, $b->label);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With