「本」のコレクションが与えられた場合、すべての「著者」を見つける最良の方法は何ですか (重複なし)?
では、古典的な関連付けがあるとしましょう:
class Author < ActiveRecord::Base
has_many :books
end
class Book < ActiveRecord::Base
belongs_to :author
end
私が今やっている方法は次のとおりです。
@books = Book.where("some condition")
@authors = Author.where(:id => @books.map(&:author_id))
それを行うより良い方法はありますか?