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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thank you for the reply.
This will work, but is there a way to do this search without adding
another association?
I am just trying to learn the capabilities of ActiveRecord.
Let me re-state the problem: I either already have the parent object,
or know enough of it's attributes to find the parent.
But the goal is to find the child, using only its 'parent' association.
Child.find (:name=>"Timmy", parent => knownParent )
- or -
Child.find (:name=>"Timmy", parent.name => "Michael")
Erol,
Thank you for the reply.
This will work, but is there a way to do this search without adding
another association?
I am just trying to learn the capabilities of ActiveRecord.
Let me re-state the problem: I either already have the parent object,
or know enough of it's attributes to find the parent.
But the goal is to find the child, using only its 'parent' association.
Child.find (:name=>"Timmy", parent => knownParent )
- or -
Child.find (:name=>"Timmy", parent.name => "Michael")
--
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 rubyonra...@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-ta...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Thanks, it did not occur to me to try this kind of finder. The second
option also works, especially "common practice" part - learning Rails
idioms here.
I initially assumed ActiveRecord would be able to build a query based
on known PK and FK attributes of the association without explicit
reference of parent's id, which would be, in my opinion, more OO
Nikolai