小编Ale*_*ara的帖子

2个用户之间的产品订单

我有三个模型:用户,产品,优惠以及这些模型之间关系的问题.

场景:

用户1发布产品

用户2可以向用户1发送价格为10美元的报价

用户1可以接受或拒绝该优惠

我现在的问题是:

用户,产品和优惠之间的正确关系是什么?

我该如何处理这些"接受或拒绝"的行为?

可能有更好的解决方案吗?

用户模型:

class User < ActiveRecord::Base
    attr_accessible :name, :email, :password, :password_confirmation, :remember_me, :avatar, :screen_name
    has_many :products
    has_many :offers,:through => :products
end
Run Code Online (Sandbox Code Playgroud)

产品型号:

class Product < ActiveRecord::Base
    attr_accessible :content, :price, :title, :tag_list, :productimage, :user_id
    belongs_to :user
    has_many :offers, :through => :users
end
Run Code Online (Sandbox Code Playgroud)

优惠型号:

class Offer < ActiveRecord::Base
    attr_accessible :offer_price, :status, :user_id, :product_id
    has_many :products
    has_many :users, through: :products
end
Run Code Online (Sandbox Code Playgroud)

提前致谢 :)

编辑:

我正在使用Rails 3.2.8

ruby ruby-on-rails relationship belongs-to

5
推荐指数
1
解决办法
1368
查看次数

标签 统计

belongs-to ×1

relationship ×1

ruby ×1

ruby-on-rails ×1