Monday, 15 August 2011

ruby on rails - ActiveRecord sort_by model's association -


Where I want to use a segment to get all the right ItemAttributes, then the column order Fixed

Relationships:

  Class item exchanges & lt; ActiveRecord :: Base is_to: static, primary_key: "name", foreign_key: "name" end class Static & lt; ActiveRecord :: Base is - Medium: Item_Authority,: foreign_key = & gt; 'Name',: primary_key = & gt;  @ objects. Sort_by (& amp; static.order)  

me Like to use the scope and to keep the maintenance of each class in its class, in this way something I stable model,

  class Static & lt; ActiveRecord :: Base area: sort_by_order, - & gt; If you want to end  

, then

  @sorted_items = ItemAttribute.joins {command (order :: desc)} # or Asc (: stable). Where (level: 5). Merge (Static.sort_by_order)  

No comments:

Post a Comment