Jables wrote:
I have what I think is a fairly complex modeling problem for you guys.
So I have a user class. There are three link type classes: picture, video, and story. A user can vote, bookmark, and add any of those types. Essentially I want to be able to say: user.stories and get the stories the user has uploaded user.votes.stories and get the votes that are stories user.votes.videos and get the votes that are videos user.bookmarks.videos and get the bookmarks for the videos
So these are essentially join tables, but I can't seem to get them to go properly, have tried polymorphism and has_many_polymorphs, limited success, limited knowledge.
Now I also want to be able to go the other way:
story.votes story.user story.bookmarks
I will be seriously impressed if anyone can tackle this
Thanks for the help, JB
class Story < ActiveRecord::Base ~ has_many :votes ~ belongs_to :user
~ end end
class User < ActiveRecord::Base ~ has_many :stories ~ has_many :votes ~ has_many :stories_voted_on, :through => :votes, :source => :story end
class Vote < ActiveRecord::Base ~ belongs_to :story, :counter_cache => true ~ belongs_to :user
end
belongs_to and has_many and their friends are what you seek.
- -- Phillip Gawlowski Twitter: twitter.com/cynicalryan
~ - You know you've been hacking too long when... ...your children do something they shouldn't do, you tell them to stop, they do it just once more anyway, so you think "Well, they prefetched the instruction and are executing it in the delay slot."