我有一个产品模型,一个状态模型和一个Productstatuses模型。使用布尔值或has_many通过?
Product has_many :productstatuses, :dependent => :destroy
Product has_many :statuses, :through => :productstatuses
Status has_many :productstatuses
Status has_many :products, :through => :productstatuses
Productstatus belongs_to :product
Productstatus belongs_to :status
我以两种方式使用状态。
一,展示产品在我们的系统中的进展情况(状态bookmark, processing, approved
。一旦产品的状态为approved
,它不能在系统中向后移动(以便我不创建公开404)产品必须具备这三个中的一个在任何时候都有效
我也对产品使用不同的“标志”的状态:。
retired
当产品不再可用(此产品也将始终有approved
状态;approved
==公开可索引在我们的地图,但retired
来自世界各地的上我们的网站(索引,归档等),删除它,而不当产品不可404'ing其永久)pre-sale
但(可能有以上三种)- 的
needs-images
(可以有任何的三个)
我的问题是有点两舞伴的:
如果我刚才提出的“标志”状态的产品型号布尔值?我问,因为:
如何编写一个范围说
approved but not retired
?或者approved but not retired and not needs-images
?
用布尔,我可以有像 scope :not_foo where(:foo = false)
和链的所有了范围。我正在用上面的设置做最好的方法来做一个空白。我认为has_many :through
的设置是要走的路(布尔人的标志在我的数据库中看起来像是多余的falses
),但数据库结构/规划并不是我的强项。
感谢您的建议。任何理由为什么过渡可以通过aasm或其他方式? – jaacob 2011-03-11 22:55:48
没有什么大的区别,只需简短地看一下它们,然后使用一个更容易启动的功能,功能提供了类似的接口 – mpapis 2011-03-11 23:05:20