I have two models, History and SalesOrder, which are setup like this: class History < ActiveRecord::Base belongs_to :sales_order end class SalesOrder < ActiveRecord::Base has_many :histories has_many :latest_history, :class_name => "History", :order => "id desc" end Is it possible to use a where clause when finding SalesOrders that is based on History? For example: orders = SalesOrder.find(:all, :order => ''latest_history asc'') Is that kind of thing even possible with Active Record? -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I think you want to pass has_many a block with your conditions... Read about it here: http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html b Jason wrote:> I have two models, History and SalesOrder, which are setup like this: > > class History < ActiveRecord::Base > > belongs_to :sales_order > > end > > class SalesOrder < ActiveRecord::Base > > has_many :histories > has_many :latest_history, > :class_name => "History", > :order => "id desc" > > end > > > Is it possible to use a where clause when finding SalesOrders that is > based on History? For example: > > orders = SalesOrder.find(:all, :order => ''latest_history asc'') > > Is that kind of thing even possible with Active Record? >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---