I'm trying to model a somewhat complicated genetic relationship in
class Gene < ActiveRecord::Base
belongs_to :species, :foreign_key => "species_id", :class_name =>
has_many :genes_orthogroups, :class_name => 'GenesOrthogroups' #
join table model
has_many :orthogroups, :through => :genes_orthogroups
has_many :orthologs, :through => :orthogroups, :source
=> :genes, :conditions => 'gene.species_id != ortholog.species_id'
class GenesOrthogroups < ActiveRecord::Base
class Orthogroup < ActiveRecord::Base
has_many :genes_orthogroups, :class_name => 'GenesOrthogroups'
has_many :genes, :through => :genes_orthogroups
belongs_to :species_pair, :class_name => 'SpeciesPair', :foreign_key
class SpeciesPair < ActiveRecord::Base
belongs_to :species1, :foreign_key => "species1_id", :class_name =>
belongs_to :species2, :foreign_key => "species2_id", :class_name =>
class Species < ActiveRecord::Base
has_many :species_pairs, :class_name => 'SpeciesPair'
I'm trying to print out a list of the orthologs with a partial. The
list is generated with:
ortholog_list = 
Gene.find(gene_id).orthologs.each do |ortholog|
ortholog_list << ortholog
I get the following error message:
Invalid source reflection macro :has_many :through for
has_many :orthologs, :through => :orthogroups. Use :source to specify
the source reflection.
If I change :source to :gene instead of :genes, I get:
Could not find the source association(s) :gene in model Orthogroup.
Try 'has_many :orthologs, :through => :orthogroups, :source =>
<name>'. Is it one of :genes_orthogroups, :genes, or :species_pair?
Essentially, any given gene should have zero, one, or multiple
orthologs in another species. These are grouped into orthogroups, each
consisting of genes from two species, and representing a many-to-many
relationship. Genes in an orthogroup which are of the same species
would be paralogs instead. Because there are more than just two
species, a gene may participate in multiple orthogroups (up to one for
each additional species). The generalization for ortholog/paralog is
"homolog" or "homologue," incidentally.
I've based most of this code on the p.369 explanation "Using Models as
Join Tables" in Agile Web Development with Rails (3rd Ed). I'm not
really sure why it fails, except for the fact that I'm trying to use
Gene as its own source for defining orthologs. What's the proper way
to define this relationship?
Apologies for the complexity of the model. I couldn't think of any
Thanks so much,