使用命名空间时,ActiveRecord属于all_to

时间:2013-02-19 23:47:19

标签: ruby-on-rails-3 rails-activerecord

我的系统会很大,所以我在命名空间中分离了模型。但是,有一个我无法建立关系的模型......

(我的模型是葡萄牙语,复数是好的)

class Sistema::Instituicao < ActiveRecord::Base  
  has_many :agencias
  has_many :dependencias, through: :agencias
  #(...)
end

class Sistema::Agencia < ActiveRecord::Base
  belongs_to :instituicao
  has_many :dependencias
  #(...)
end

class Sistema::Dependencia < ActiveRecord::Base
  belongs_to :agencia
  belongs_to :instituicao, through: :agencia
  #(...)
end

但我在Dependencia中收到错误,如下所示:

ArgumentError: Unknown key: through

我没看到什么?

谢谢!

1 个答案:

答案 0 :(得分:0)

如果查看api for belongs_to,您会看到没有:through选项。 :through选项仅适用于has_onehas_many关联