Forum: Ruby on Rails ActiveRecord: querying children

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
578f6d71f9a338772994b622dd51d86d?d=identicon&s=25 bataras (Guest)
on 2006-12-27 20:21
(Received via mailing list)
I have a parent with has_many children. The children have a column
'blah'. IF I do the following:

    parent.children.find_by_blah(42)

The sql exectued is:

    select * from blah where parent_id = 1 and blah = 42
    select * from blah where parent_id = 1

The first line of sql is what I want. The second appears to be
ActiveRecord loading up all of parent.children. This I don't want b/c
children is huge.

How do I avoid that and use idiomatic ActiveRecord?

thanks
This topic is locked and can not be replied to.