Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

eager loading polymorphic has_one association with conditions generates incorrect sql

#604

Given the following association in an "Org" model:

has_one :primary_address, :class_name => "Address", :as => :addressable, :conditions => { :primary => true }

The following query will be generated if you don't use :include and reference the primary_address:

SELECT * FROM "addresses" WHERE ("addresses".addressable_id = 1 AND "addresses".addressable_type = E'Org' AND ("addresses"."primary" = 't')) LIMIT 1

but if you do an "Org.find" and :include => :primary_address, you get the following, incorrect sql during the address load:

SELECT "addresses".* FROM "addresses" WHERE ("addresses"."addressable_id" IN (1) and "addresses"."addressable_type" = 'Org' AND ("orgs"."primary" = 't'))

Here, it's applying the conditions hash to the Org, rather than to the Address.

Reported by Jeremy McNevin · July 12th, 2008 @ 12:27 AM

State: stale
Milestone: 2.x
Assigned to: nobody
Importance: none

Activity

  1. josh
    josh
    • State changed from new to stale

    October 23rd, 2008 @ 04:32 PM