Noob here. I have a rails app that has users and postings. I need to add buyers, which are users.
Users can post things, but can also view others posts and then select to buy those posts.
I am not sure ho开发者_JAVA技巧w to setup this in my posts or users model.
You can setup something like this,
You can add a field to posts, buyer_id
In Model Posts
belongs_to :user
belongs_to :buyer, :class => "User", :foreign_key => "buyer_id"
In Model User
has_many :posts
has_many :purchases, :class => "Post", :foreign_key => "buyer_id"
This is one way of doing things.
精彩评论