Ruby on Rails

Through

class Author < ActiveRecord::Base
  has_many :authorships
  has_many :books, :through => :authorships
end

class Authorship < ActiveRecord::Base
  belongs_to :author
  belongs_to :book
end

@author = Author.find :first
@author.authorships.collect { |a| a.book } # selects all books that the author's authorships belong to.
@author.books                              # selects all books by using the Authorship join model



José M. Vidal .

8 of 16