3460 Posts in 1064 Topics by 739 members
|Go to End|
8 March 2009 at 5:58am Last edited: 8 March 2009 7:44am
I have a an AttributeValue DataObject, with has_one relation to the Attribute it is a value of. When listing the attribute values I want them sorted by a "Weight" parameter set in the Attribute. So I have a method in the controller for my class applying the attributes named SortedAttributeValues(). But I can not get it working. Can ofc make my own sorting algorithm but would rather figure out how to use the built in.
// Turned out the sorting method does a $obj->$column when comparing.
I'm very grateful if someone has some ideas to throw my way.
EDIT: Simplified the problem.
9 March 2009 at 10:07am
The ProductAttributeValues() method can take, filter, sort, join, and limit arguments.
See http://api.silverstripe.com/sapphire/model/DataObject.html#getComponents - the first argument to that method is automatically set to the string "ProductAttributeValues".
In other words
calling $this->ProductAttributeValues($f, $s, $j, $l);
internally calls $this->getComponents("ProductAttributeValues", $f, $s, $j, $l);
10 March 2009 at 7:48am
Thanks a lot Sam, works perfectly. I just had to type the join for ProductAttribute.
return $this->ProductAttributeValues('', 'ProductAttribute.Weight', 'INNER JOIN ProductAttribute ON ProductAttributeValue.ProductAttributeID = ProductAttribute.ID');
Of course it would be even nice to have it sorted by $default_sort, but I guess it's hard to get that working with the sort value in a related table?
|Go to Top|