Carp
2007-Nov-20 21:26 UTC
Adding :order to the find method using a self-referencing model
My issue is with a single table, Conferences, that uses a column parent_id to reference itself. This way, I identify big conferences (like NCAA) and the smaller conferences that make it up (like PAC 10). What I''d like to do is use the :order modifier of the find method to sort each conference by it''s parent''s name. The best I''ve gotten so far is being able to sort by the parent''s ID (which isn''t particularly helpful). One thought was to change my reference column from parent_id to parent_name (and force these to be unique). However, I''m guessing that would break the :counter_cache functionality. Anyone know what I should do? Thanks. #model class Conference < ActiveRecord::Base has_many :teams belongs_to :conference, :foreign_key => "parent_id", :counter_cache => true end #table columns id name abbr parent_id conferences_count teams_count #controller @conferences = Conference.find(:all, :order => ''parent_id'') --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---