私はUser
モデルとのhas_many :through
関係を持つモデルを持っていPublication
ます。Publication
モデルは次の関係has_many :through
にありAuthor
ます。
class User < ActiveRecord::Base
has_many :library_publications, :dependent => :destroy, :class_name => "Library::Publication"
has_many :publications, :through => :library_publications
end
class Library::Publication < ActiveRecord::Base
belongs_to :publication
belongs_to :user
end
class Publication < PublicationBase
has_many :library_publications, :dependent => :destroy, :class_name => "Library::Publication"
has_many :users, :through => :library_publications
has_many :publication_contributions, :dependent => :destroy, :class_name => "Publication::Contribution"
has_many :authors, :through => :publication_contributions
end
class Author < AuthorBase
has_many :publication_contributions, :dependent => :destroy, :class_name => "Publication::Contribution"
has_many :publications, :through => :publication_contributions
end
class Publication::Contribution < Publication::ContributionBase
belongs_to :publication, :class_name => "Publication"
belongs_to :author, :class_name => "Author"
end
私が知る限り、すべての関連付けは正しく書かれています。ただし、ユーザーから作者をeagerloadしようとすると:
@user.library_publications.includes(:publication => [:authors])
次のエラーが表示されます。
Association named 'authors' was not found; perhaps you misspelled it?
これの原因は何ですか?