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.


3 Posts   1236 Views

Capt. Morgan

8 March 2009 at 5:58am (Last edited: 8 March 2009 7:44am), Community Member, 30 Posts

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 Administrator, 679 Posts

The ProductAttributeValues() method can take, filter, sort, join, and limit arguments.

See - 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);

Capt. Morgan

10 March 2009 at 7:48am Community Member, 30 Posts

Thanks a lot Sam, works perfectly. I just had to type the join for ProductAttribute.

function SortedProductAttributeValues()
   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?