3
我有一個屬於「Store」(has_many「products」)的模型「Product」。 我想驗證產品名稱的唯一性,但僅限於每個商店內。Rails validates_uniqueness_of:作用域上的外鍵
現在我有這樣的:
class Product < ActiveRecord::Base
belongs_to :store
validates_uniqueness_of :name, :scope => :store_id
end
當我運行保存的任何一款產品,現在我得到:
SQLite3::ConstraintException: column name is not unique
我敢肯定有一個簡單的錯誤,我在這裏做。請教育我。
感謝,
哈里斯
謝謝布萊恩,約束是問題。 – lightyrs 2011-02-11 21:06:08