On Aug 9, 2:09 pm, Rahul <[email protected]> wrote:
> Hi,
>
>           Consider this scenario, I have a table which stores the
> "likes" and it would stores the likes from all sorts of tables like
> blogs,comments, postings, reviews, etc. So the table has the following
> columns(id, like_id and type) where like_id is the id from any of the
> previous mentioned tables and type would be single char column to
> identify the foreign key table(B for blog, C for comments and so on).
> How am i supposed to create the relation between like table and the
> other tables?

Check out the :polymorphic option to belongs_to - it does exactly what
you're describing, except for the (premature) "optimization" of
storing a single character for the type.

--Matt Jones

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to