开发者

Users model also need to be buyers

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜