所以我有以下型號:模擬這些數據庫關聯的最佳方式是什麼?
- 用戶
- 業務
- 券
- 優惠
- 贖回
- 所有者
我現在用的是所有者模型關聯各種其他模式,如商業優惠券交易s並且可兌換成用戶模型。
使用可兌換模型是因爲我想爲每個使用優惠券/交易的用戶生成一個唯一的代碼,以限制每個用戶一個以及總額。
我想也許我不需要兩種模式的優惠券和交易,我只需要一個,因爲交易更像是一種特殊類型的優惠券。
因此,繼承人修訂後的機型:
Business
has_many :owners, :as => :ownable, :dependent => :destroy
has_many :coupons, :dependent => :destroy
Coupon
belongs_to :business
has_many :redeems
# also has a special column for denoting weather it's a
# normal coupon or a daily deal kind of coupon
Redeem
belongs_to :coupon
has_one :owner, :as => :ownable, :dependent => :destroy
Owner
belongs_to :user
belongs_to :ownable, :polymorphic => true
和用戶模型,我只是完全失去了 但這裏是我想要的僞代碼只是所有這些 編輯誰可以在這裏的有同樣的問題我如何建立用戶模型
User
has_many :owners
has_many :businesses, :through => :owners,
:source => business, :source_type => 'Business'
has_many :redeems, :through => :owners, :source=> :redeem,
:source_type => 'Redeem'
has_many :coupons, :through => :redeems,
:source => :coupon, :source_type => 'Coupon'
我只是不知道如何,因爲我做的東西擁有一個多態關聯的優惠券與用戶模型相關聯。
考慮到兌換是一個形容詞,這將把它作爲一個對象的屬性或一個表的一列。作爲動詞(贖回)它將由一個關聯表示。你有它作爲一個實體(對象),所以有些東西在這裏。也許你可以描述你想要建模的過程? –