使用委托属性Rails validates_uniqueness_of

时间:2014-03-07 17:17:21

标签: ruby-on-rails ruby validation activerecord

尝试范围:名称为View的父级:表单

上的属性
class View < ActiveRecord::Base
  belongs_to :form
  delegate :facility_id, to: :form
  validates_uniqueness_of :name, scope: :facility_id
  attr_accessible :name

为什么不在表单上查找facility_id?

而是在View

上查找它
ActiveRecord::StatementInvalid - PG::UndefinedColumn: ERROR:  column views.facility_id does not exist

1 个答案:

答案 0 :(得分:0)

我相信这段时间以前曾经有过工作,很有可能它仍然有效:

validates_uniqueness_of :name, scope: { :form => :facility_id }