Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #11154 (closed defect: fixed)

Opened 1 year ago

Last modified 1 year ago

Don't assume all records from nested include are of same class

Reported by: acechase Assigned to: nzkoz
Priority: normal Milestone: 2.1
Component: ActiveRecord Version: edge
Severity: normal Keywords: activerecord eager loading preloading
Cc: bitsweat, tarmo, lifofifo, chuyeow, jbarnette, ian.w.white@gmail.com, michael@schuerig.de, acechase

Description

There is an error condition with nested includes in this situation:

ShapeExpression.find :all, :include => [:shape, { :paint => :non_poly } ]

In the include used above, :paint is a polymorphic relationship, therefore, the association to :non_poly is not necessarily the same for all :paint objects. However, as currently implemented, the eager include code will try to load all :non_poly associations using the association information from the first :paint object it checks. The test 'eager_load_nested_include_test.rb' demonstrates the problem using a simple object graph (with class defs provided at the bottom of the file).

The patched version of AssociationPreload#preload_one_association first sorts the record by class then preloads each group of sorted records.

Attachments

fix_nested_include_with_mixed_record_type.patch (5.1 kB) - added by acechase on 02/18/08 19:17:13.
patch top AR::AssociationPreload#preload_one_association (+ test)

Change History

02/18/08 19:17:13 changed by acechase

  • attachment fix_nested_include_with_mixed_record_type.patch added.

patch top AR::AssociationPreload#preload_one_association (+ test)

02/18/08 19:18:33 changed by acechase

sorry, that should read: patch to AR::AssociationPreload#preload_one_association (plus test)

02/19/08 02:56:12 changed by bitsweat

  • status changed from new to closed.
  • resolution set to fixed.

(In [8896]) Don't assume all records from nested include are of same class. Closes #11154 [acechase]

02/19/08 06:01:58 changed by bitsweat

(In [8897]) Remove mysql option from a test that applies to all databases. References #11154.