Topic: How to handle one object related to multiple objects (eg comments)

Let's say you want to create a comment object/table and you have multiple objects/tables that have a relationship (one to many) to that comment object.

Can you have multiple belongs_to definitions in the comment object:
belongs_to :news_articles
belongs_to :people
etc...

Or am I better off rolling my own and creating a join table with
owner_type
owner_id
(understanding the limitations on enforcing database integrity
through foreign keys in this situation).

I'm just wondering if rails has a nifty way of dealing with the issue
or I should use my old approach.

Thanks,
-xdotcommer

Re: How to handle one object related to multiple objects (eg comments)

You might be relieved to find that Rails supports just this kind of relationship natively.  It's called a 'polymorphic' relationship where one model can belong_to a number of others.

http://wiki.rubyonrails.org/rails/pages … sociations

Re: How to handle one object related to multiple objects (eg comments)

Woo Hoo!

Thanks a lot
-xdotcommer