Conflicting Attributes in Model and Join Table

Hi all,

I’ve got a Post and User classes. The Post has a user_id attribute to
point to the user that created it.

I want to implement favorites, so I made Post and User both
“has_and_belongs_to_many” and created a favorites join table. The
join table has a post_id and a user_id column.

Now when I get my post everything seems to be okay, but in some
contexts, the user_id get’s overwritten. I think that the user_id
from the join table is being merged into my Post instance.

What would you do differently so that there was no collision between
my Post’s user_id (the author) and the join table’s user_id (for whom
this post is a favorite)?


Bradley M.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs