ActiveRecord question - how to find owners of at least one c

Hopefully the subject is clear enough.

Let’s say I’ve got two tables:

create_table :bands do | b |
b.column :name, :string

create_table :concerts do | c |
c.column :where, :string
c.column :when, :date
c.column :band_id, :integer

and the models:

class Band <<ActiveRecord::Base
has_many :concerts

class Concert << ActiveRecord::Base
belongs_to :band

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?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs