How do I define a foreign key that points to a class of a different name in ActiveRecord with Rails?

Posted by Mark on Stack Overflow See other posts from Stack Overflow or by Mark
Published on 2011-01-12T03:59:59Z Indexed on 2011/01/12 5:53 UTC
Read the original article Hit count: 174

Filed under:
|
|

Hi there,

I have a model Follow that defines a user_id and a followed_user_id. If you've used Twitter, this should make sense.

I'm trying to make followed_user_id point to a User model, so I can access the user that is being followed through f.followed_user (in the same way that if I have an Entry with belongs_to :user and a user_id column I can use entry.user to get the user.)

How can I do this?

Thanks!

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about activerecord