Ruby on Rails Friday, January 27, 2012

Well, frankly, if I were you, I would read the documentation again. It doesn't seem like you know what a polymorphic association is. You described a standard has_many relationship.

Polymorphic association is when one model belongs to several different models. For example, to use the Rails casts episode, a comment can belong to a Photo, a Post, or a Product.

From what you have written so far, it seems like you want a standard has_many and belongs_to association.

User has_many :posts will let you do @user.posts, and a Post belongs_to :user will let you do post.user. If you want customize the name of the association, as in post.author, then I think you need to use the :class_name


--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/hwFc1eURfFwJ.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment