Hello there, newbie speaking Let's say I have: class Office has_many :holidays #(just a list of dates when the office is closed) has_many :doctors #doctors who work in the office end class Doctor belongs_to :office has_many :holidays #(additional dates when this doctor is not available) end class Holiday (has a office_id, doctor_id and a date field) end From the app standpoint I would like to be able to allow the administrator to set office-wide closed dates, but to allow an individual doctor to augment that list with additional dates he/she won't be available in. What is the best/most elegant way to retrieve the merged list of holidays for a doctor? I know I could retrieve the Office holidays in the doctor model and merge it with the Doctor's holidays, but I was wondering if there was a more activerecord/rails-specific pattern that I might be missing to allow one DB query with the 'inherited' holidays from the Office.... Thanks Enrico.
on 2009-04-10 17:57
on 2009-04-10 20:50
I don't know if this might work, but you could give it a shot. class Doctor belongs_to :office has_many :holidays, :through => Office, :conditions => ['doctor_id = NULL OR doctor_id = ?',self.id] end There's a very good chance this might not work, so perhaps instead of an association, maybe you could use a named_scope instead. On Apr 10, 11:57 pm, Enrico Brunetta <rails-mailing-l...@andreas-