Hi. Thanks for your answer..
It's not quite what i'm looking for. I need to be able to call up a list of upcoming (or past) events that a specific user has, with a different EventAttendee state. I managed to but in an additinal scope in the user model for each state, like this: has_many :managing_event_attendees, :class_name => "EventAttendee", :scope => :manager has_many :managing_events, :through => :managing_event_attendees, :source => :event So now i can call ex. ¤t_user.managing_events.upcoming to get a list of the upcoming events the user manages. It's not pretty, and i think there might be a more desirable way to do it. Do you have any suggestions? Thanks in advance..! :) On 16 Mar., 15:35, Bryan Larsen <[email protected]> wrote: > Note 1: some of your named_scopes are unnecessary. > Seehttp://cookbook.hobocentral.net/manual/scopes#lifecycle_scopes > > The easy way is: > > Event.upcoming.map {|event| event.attendees.managers} > > or equivalently: > > Event.upcoming.*.attendees.*.managers > > But if you have a lot of upcoming events that do not have managers, this > will be database inefficient. > > So you can construct a named_scope like so: > > class EventAttendee < ActiveRecord::Base > named_scope :upcoming_managers, :include => :event, :conditions => > ['events.start_time > ? AND state = ?', Time.now, "manager"] > end > > > > Mikkel WF wrote: > > I need to get some user specific data out of my application. > > > The model is as such: > > > class Event < ActiveRecord::Base > > has_many :event_attendees, :dependent => :destroy > > has_many :attendees, :through => :event_attendees, :accessible => > > true, :source => :user, :scope => :activated > > named_scope :upcoming, :conditions => ['start_time > ?', Time.now()] > > named_scope :past, lambda { {:conditions => ['start_time < ?', > > Time.now()]} } > > end > > > class User < ActiveRecord::Base > > has_many :event_attendees, :dependent => :destroy > > has_many :events, :through => :event_attendees > > named_scope :activated, :conditions => { :state => > > ["new","loosely","active","manager"]} > > named_scope :managers, :conditions => { :state => ["manager"]} > > end > > > class EventAttendee < ActiveRecord::Base > > belongs_to :event > > belongs_to :user > > named_scope :attending, :conditions => { :state => ["volunteer", > > "manager"], } > > named_scope :managers, :conditions => { :state => ["manager"], } > > lifecycle do > > state :available, :default => true > > state :volunteer > > state :manager > > end > > end > > > I need to display: > > - A list of events a user has to participate in in the future > > - A list of events a user has participated in > > > This is easy enough with the :past and :upcoming scopes. > > > BUT!, i also need to display a list of a users upcoming events based > > on the status of the lifecycle state in EventAttendee. > > I simply cannot grasp how to do this..! > > I can display a list of EventAttendees associated to a user, and based > > of the state, but how can i also apply some kind of search to if the > > associated Event is in the past or in the future.. > > > Help is 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 at http://groups.google.com/group/hobousers?hl=en.
