私は、著者、本、著者と呼ばれる3つのモデルを持つレールアプリを持っています。本には、オーサーシップと呼ばれる共同モデルを通じて多くの著者がいて、著者はオーサーシップと呼ばれる共同モデルを通じて多くの本を持っています。
class Author < ActiveRecord::Base
attr_accessible :name
has_many :authorships
has_many :books, :through => :authorships
end
class Book < ActiveRecord::Base
attr_accessible :name, :author_ids
has_many :authorships
has_many :authors, :through => :authorships
end
class Authorship < ActiveRecord::Base
attr_accessible :book_id, :author_id
belongs_to :book
belongs_to :author
end
今、私の質問は、類似の著者として選択された本をどのように見つけることができますか?
たとえば、<% book = Book.first %>
次のようなもの
<% book.similar_authors.each do |book| %>
#......
<% end %>
定義に使用するクエリの種類similar_authors