我希望有人已经经历过这一点。请帮助我,我该如何解决这个问题:
class Article < ActiveRecord::Base
belongs_to :author
belongs_to :publisher
has_one :address, :through => :publisher
end
class Author < ActiveRecord::Base
has_many :articles
has_many :addresses, :through => :articles, :source => :address
end
我尝试获取“作者”的“地址”,但在控制台中出现此错误:
ActiveRecord::HasManyThroughSourceAssociationMacroError: Invalid source reflection macro :has_one :through for has_many :addresses, :through => :articles. Use :source to specify the source reflection.
但author.articles[0].address
工作正常。
我希望你给我建议,我该如何解决它。谢谢。