This project is archived and is in readonly mode.
eager loading polymorphic has_one association with conditions generates incorrect sql
Reported by Jeremy McNevin | July 12th, 2008 @ 12:27 AM | in 2.x
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.
Comments and changes to this ticket
-
josh October 23rd, 2008 @ 04:32 PM
- State changed from new to stale
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>