当我尝试使用has_many:through关联时,它似乎在连接表中查找通用键。实施例
class Ots::Foo < ActiveRecord::Base
has_many :foo_bars, :class_name => '::Ots::FooBar', :foreign_key => :ots_foo_id
has_many :bars, :class_name => '::Ots::Bar', :through => :foo_bars
end
class Ots::Bar < ActiveRecord::Base
has_many :foo_bars, :class_name => '::Ots::FooBar', :foreign_key => :ots_bar_id
has_many :bars, :class_name => '::Ots::Bar', :through => :foo_bars
end
class Ots::FooBar < ActiveRecord::Base
belongs_to :foo, :class_name => "::Ots::Foo", :foreign_key => :ots_foo_id
belongs_to :bar, :class_name => "::Ots::Bar", :foreign_key => :ots_bar_id
end
f = Foo.find(1)
f.bars =># invalid column name 'bar_id'
这是我应该期待的吗?命名空间是否有更优雅的解决方案?