rick.denatale-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Sep-03 20:22 UTC
ActiveRecord question - how to find owners of at least one child with a conditional
Hopefully the subject is clear enough. Let''s say I''ve got two tables: create_table :bands do | b | b.column :name, :string end create_table :concerts do | c | c.column :where, :string c.column :when, :date c.column :band_id, :integer end and the models: class Band <<ActiveRecord::Base has_many :concerts end class Concert << ActiveRecord::Base belongs_to :band end What I''d like to do is find all of the Bands which have at least one concert on or after a given date. In this case there are lots of concerts which makes this a bit performance critical. I''ve not been able to figure out how to do this through ActiveRecord so as to generate an efficient SQL query, or how to do it manually using find_by_sql either. It''s a bit complicated also since SQL date comparison function seems to be somewhat database dependent. Any ideas from the community? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---