Forum: Ruby on Rails Get a collections parent model.

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Bbae56dedb7ef0a5c219065a033859ea?d=identicon&s=25 twoism (Guest)
on 2008-10-20 20:31
(Received via mailing list)
Is there away get a collections parent model from within the
collection itself? Where the collection looks like this:

User.first.events.upcoming
or
Group.first.events.upcoming.

If the upcoming method is in a mix-in that is shared by two different
models how could you find what the parent model is (Group or User)?
Bbae56dedb7ef0a5c219065a033859ea?d=identicon&s=25 twoism (Guest)
on 2008-10-20 21:19
(Received via mailing list)
Found it:

proxy_owner

User.first.events.upcoming

def upcoming
  case self.proxy_owner.class
  when User
   # do stuff for User
  when Group
  # do stuff for groups
  else
  end
end
This topic is locked and can not be replied to.