我有一个Measure table
并且有以下字段
Class Measure < ActiveRecord::Base
id
Title
Question_id
Answer_id
Answer_text
end
我有Package table
一列
Class Package < ActiveRecord::Base
id
Package_name
end
我有package_measure
桌子
Class PackageMeasure < ActiveRecord::Base
belongs_to :measure, foreign_key: 'measure_id', primary_key: 'id', class_name: 'Measure'
id
package_id
measure_id
end
现在的问题是Package_measure
表。我可以measures
为单个选择多个package
,我创建了一个hash
并且它工作正常。我不想将相同添加question_id
到相同的package
. 我怎样才能做到这一点?
我想做如下的事情:
validates_uniqueness_of :package_id, :scope => measure.question_id