开发者

Users model also need to be buyers

开发者 https://www.devze.com 2023-02-13 12:21 出处:网络
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.

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

精彩评论

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