I’d like to get your feedback on the easiest way to find records that
are related via has_many :through based on options in the :through
table. Suppose an Author has_many Books :through a table called
Authorships. The Authorships table is defined as:
create_table “authorships”, :force => true do |t|
The “role” can either be “contributor” or “primary author”. The model
class Author < Active Record::Base
has_many :books, :through => :authorships
class Book < ActiveRecord::Base
has_many :authors, :through => :authorships
class Authorship < ActiveRecord::Base
So supposing I have a Book, how can I find all of the authors whose
role is defined in the :through table as “contributor”?
Similarly, if I have an author, how can I find all of the books that
the author is the “primary author” of?