Polymorphic association in reverse
Posted
by Erik
on Stack Overflow
See other posts from Stack Overflow
or by Erik
Published on 2010-03-17T15:58:52Z
Indexed on
2010/03/17
16:01 UTC
Read the original article
Hit count: 380
ruby-on-rails
|ruby-on-rails3
Let's say that I have two models - one called Post and one other called Video. I then have a third model - Comment - that is polymorphically associated to to each of these models.
I can then easily do post.comments and video.comments to find comments assosciated to records of these models. All easy so far.
But what if I want to go the other way and I want to find ALL posts and videos that have been commented on and display these in a list sorted on the date that the comment was made? Is this possible?
If it helps I'm working on Rails 3 beta.
© Stack Overflow or respective owner