Suppose that we have Radio Stations which play Songs by means of a
License.
=======
class Song
has_many :licenses
has_many :radio_stations, :through => :licenses
end
class RadioStation
has_many :licenses
has_many :songs, :through => :licenses
end
class License
belongs_to :radio_station
belongs_to :song
end
Licenses are either active or not. Given a Song, we want to know which
Licenses are active. If that information was on Song instead, we could
just do something like:
scope :licensed_for_radio_station, lambda { |rs|
where(:licensed_stations => rs) }
But we can’t, since it’s on License instead. So, two questions:
1.) Given a Song, we want to know which Licenses are active.
What’s the most idiomatic way to do this? Association method? Scope?
etc.
2.) Given a Song and a RadioStation, what’s the most idiomatic way
to find the association that links them?
3.) Given a Song and a RadioStation, what’s the most idiomatic way
to modify the corresponding license to have :active => true?
Any thoughts are appreciated. Thanks!
~ jf