My response earlier was definitely quick-and-dirty. ActiveRecord (depending
on the version) should be filtering your joined (eagerly loaded)
associations for you, based on the association owners id (in your case the
location id). The query it generates should look something like this:
SELECT ... FROM `locations` LEFT OUTER JOIN `subcategories` ON
subcategories.location_id = locations.id WHERE (`locations`.`id` =
#{loc_id})Can you help me out by telling me what version of Rails you're running? --Jordan On Sun, May 4, 2008 at 3:51 PM, liquid_rails <[EMAIL PROTECTED]> wrote: > > Hi > > Do you know if there is a way to filter eagerly loaded models before > they are loaded from the database? Say I want to find a location by > its id, and in the same query load only subcategories where > subcategory.location_id = location.id. Right now I have this, but all > subcategories are getting loaded which is not what I want. > > @location = Location.find(loc_id, :include => [:subcategories]) > > Thanks! > > > -- Jordan A. Fowler 2621 First Ave Apt 5 San Diego, CA 92103 E-mail: [EMAIL PROTECTED] Website: http://www.jordanfowler.com Phone: 406.546.8055 --~--~---------~--~----~------------~-------~--~----~ SD Ruby mailing list [email protected] http://groups.google.com/group/sdruby -~----------~----~----~----~------~----~------~--~---
