class Parent < Entity
  has_many :children
end

p = Parent.find_by_name("Michael")
p.children # Returns all children of the parent

HTH

On Sat, Oct 16, 2010 at 4:01 AM, Nikolai Teleguine <[email protected]>wrote:

> ---
> class Child < Entity
>  belongs_to :parent, :foreign_key => 'parent_id'
> end
>
> class Parent < Entity
> end
>
> class Entity < ActiveRecord::Base
> end
> ---
>
> p = Parent.find_by_name( "Michael" )
>
> How do I find children of this parent, given that I have the identity
> of the parent?
> Can I do it without referring to parent entity attributes/values
> directly ? Something like
>
> Child.find :parent => p
>
> Rails version is 2.1.0, if that matters.
>
> --
> 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]<rubyonrails-talk%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-talk?hl=en.
>
>


-- 
Erol M. Fornoles
http://erolfornoles.posterous.com
http://github.com/Erol
http://twitter.com/erolfornoles
http://ph.linkedin.com/in/erolfornoles

-- 
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