Skip to main content
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
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.
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);
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?