开发者

How to apply :include in this scenarion?

开发者 https://www.devze.com 2023-02-02 09:40 出处:网络
modules=MenuModule.all(:order => \"module_seq\") modules.each do |m| groups=m.menu_groups.all(:order => \"group_seq\")
modules=MenuModule.all(:order => "module_seq")
modules.each do |m|
  groups=m.menu_groups.all(:order => "group_seq")
  groups.each do |g|
    items=g.menu_item开发者_Go百科s.all(:order => "item_seq")
    items.each do |i|
      puts i.name
    end
  end
end

UPDATE How to use include with order ?

Something like MenuModule.find(:all,:include => {:menu_groups(:order => "group_seq"), :menu_items(:order => "item_seq")},:order => "module_seq")

Is it possible ?


See: http://www.arraystudio.com/as-workshop/nested-include-activerecord-option.html

 MenuModule.all(:include => [{:menu_groups, :menu_items}], :order => 'module_seq,modules.group_seq,modules.groups.item_seq') 

If the item_seq is not what you want to sort on, you probably can sort using the ruby sort method. The mysql order clause in a nested join only will order by one constrain in the join, as far as I am aware.

0

精彩评论

暂无评论...
验证码 换一张
取 消