The plural model name comes from the Agile Development book. They have
an example--categories_products, linking categories to products--which
they turn into a model. Should it be renamed category_product? Or is
categories_product correct? I'm a bit confused about this, so thanks
for bringing it up.

I'll look around for the plugin. Thanks so much, Matt!

John


On Jun 29, 10:46 am, Matt Jones <[email protected]> wrote:
> The :orthologs association is the problem - Rails doesn't support
> nesting :through associations. I recall there being a plugin around
> someplace to do it, so you may want to look into that.
>
> Depending on what you need, a simple instance method may work as well.
> For example (on Gene):
>
> def orthologs
>   genes_orthogroups.ortholog_groups_for(self).map { |g| g.gene }
> end
>
> On GenesOrthogroup:
> named_scope ortholog_groups_for { |g| { :include => :gene, :conditions
> => ['genes.species_id != ?', g.species_id] } }
>
> (not tested, but should be close to working)
>
> A couple general things:
>
> - model names should be singular (GenesOrthogroup rather than
> GenesOrthogroups). Otherwise you'll eventually run into issues.
>
> - when writing SQL fragments in conditions, table names are plural (so
> genes.whatever rather than gene.whatever).
>
> - the association macros have sensible defaults, so you can leave some
> options out. For instance, the :species association in Gene can be
> simplified to 'belongs_to :species' - Rails will find the correct FK
> (species_id) and class (Species).
>
> --Matt Jones
>
> On Jun 28, 8:07 pm, John Woods <[email protected]> wrote:
>
> >   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'
> > end
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to