Can active record support: 'find' parent objects, but filter

Hi,

Can active record handle the following? Or do I need to stick to
“.find_by_sql” to do this:

select parent.id, parent.title, parent.description from parent, child
where parent.id = child.parent_id AND child.memo like
‘%texttosearch%’

That is, I want to effectively ‘find’ parent objects, but filtered based
on
the contents of it’s associated child objects data. So the question is
if
it is possible what would the ruby code be to do this? i.e. results =
Parent.find(:all, …

Thanks
Greg

if you take your query
and break it up into the following sections [:select, :from,
:conditions]

then you’ll be able to do

find(:all,
:select => “parent.id, parent.title, parent.description”,
:from => “parent, child”,
:conditions => [
“parent.id = child.parent_id AND child.memo like ?”,
“%#{texttosearch}%”
]
)

Greg H. wrote:

Hi,

Can active record handle the following? Or do I need to stick to
“.find_by_sql” to do this:

select parent.id, parent.title, parent.description from parent, child
where parent.id = child.parent_id AND child.memo like
‘%texttosearch%’

That is, I want to effectively ‘find’ parent objects, but filtered based
on
the contents of it’s associated child objects data. So the question is
if
it is possible what would the ruby code be to do this? i.e. results =
Parent.find(:all, …

Thanks
Greg