thanks, but this doesn't bring back Relationships, it brings back
Nodes...does a named_scope always bring back instances of the class it's
specified in it does it?

I really want a "named_scope", or "has_many" version of the method
"all_relations" in my original email below....any more ideas anyone?

thanks


2009/4/15 Matt Jones <al2o...@gmail.com>

>
> You could try:
>
> named_scope :all_relations_for, lambda { |o| { :conditions =>
> ["node_id = :o_id OR dependant_node_id = :o_id", { :o_id =>
> o.id }] } }
>
> That will let you do:
>
> Node.all_relations_for(Node.find(1)) etc.
>
> Not quite as snazzy as what you're looking for, but close...
>
> --Matt Jones
>
> On Apr 13, 6:26 pm, Greg Hauptmann <greg.hauptmann.r...@gmail.com>
> wrote:
> > PS.  To further clarify my question note that:
> >
> > -----------------------------------
> > class Node < ActiveRecord::Base
> >   has_many :relationships_as_child, :class_name => 'Relationship',
> > :foreign_key => :dependant_node_id
> >   has_many :relationships_as_parent, :class_name => 'Relationship',
> > :foreign_key => :node_id
> >
> >   def all_relations
> >     Relationship.find(:all, :conditions => ["node_id = ? OR
> > dependant_node_id = ?", self.id, self.id])
> >   end
> > -----------------------------------
> >
> > I can get the first two "has_many" working, but I can't work out how to
> > effectively combine these two into one "has_many".   I can create a "
> > all_relations" method however that does provide the full flexibility of a
> "
> > has_many" or a "named_scope" version (which I'm after) as I can't then do
> > further things like:
> >
> >    Node.find(1).all_relations.find(1)   # fails
> >
> > So in other words I want the output of the "all_relations" function, but
> in
> > the form of a "has_many" or a "named_scope".
> >
> > Any help welcomed  :)
> >
> > 2009/4/13 Greg Hauptmann <greg.hauptmann.r...@gmail.com>
> >
> >
> >
>
> >
>


-- 
Greg
http://blog.gregnet.org/

--~--~---------~--~----~------------~-------~--~----~
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 rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to