This project is archived and is in readonly mode.

#465 ✓Resolved
Christian Weyer

Full class name STI not included in eager loading

Reported by Christian Weyer | June 21st, 2008 @ 02:15 PM

When eager loading a polymorphic association, it does not care about the full class name (with module) in the associated type column (attached_type in the following example).


class Shared::Address

belongs_to :attached, :polymorphic => true


class Company::Base

has_one :address, :as => :attached, :class_name => 'Shared::Address'


When saving the association the attached_type column in the addresses table says correctly Company::Base.

Eager loading the company's address however produces this query: Shared::Address::Load (0.000539) SELECT "addresses".* FROM "addresses" WHERE ("addresses"."attached_id" IN (1) and "addresses"."attached_type" = 'Base')

Attached_type is incorrectly set as "Base" where it should be "Company::Base". Therefore this results in company.address being nil.

Note that only eager load is affected. Loading the association on demand works.

Comments and changes to this ticket

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=""></a>

Referenced by