don't know of a database agnostic way to do it but you can do it with sql. you need to compare a count of records pointing to the event_id to the value in the event row. my sql is too rusty to do from memory, might be GROUP or might be straight up under COUNT()
On May 4, 6:20 am, Mikkel WF <[email protected]> wrote: > Hi guys.. > > I have a problem with a scope for one of my models. > The models a roughly like this: > > class Event > fields do > attendees_needed :integer > end > has_many :event_attendees, :dependent => :destroy > has_many :attendees, :through => :event_attendees, :accessible => > true > end > > class EventAttendee > belongs_to :event > belongs_to :user > > lifecycle do > state :available, :volunteer, :manager > end > named_scope :attending, :conditions => { :state => ["volunteer", > "manager"], } > end > > I need to scope the events for which that does not have sufficient > attendees. I've made a scope in EventAttendee that returns the > attendees that are actually attending, so i need to compare this count > with the attendees_needed integer, all resulting in a scope for the > Event model. > > But i cannot get my head around doing that, so help is very much > appreciated.. > > -- > You received this message because you are subscribed to the Google Groups > "Hobo Users" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group > athttp://groups.google.com/group/hobousers?hl=en. -- You received this message because you are subscribed to the Google Groups "Hobo Users" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/hobousers?hl=en.
