0

我有一个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
4

0 回答 0