rails/rails — pull request #14532 by thedarkone (2014-03-30 19:52:15+00:00)
Title: Fix polymorphic preloads on NOT NULL _type columns

This fixes an inconsistency between semi-duplicate code in `Associations::Preloader#association_klass` and `Associations::BelongsToPolymorphicAssociation#klass`. Related to #1187.

After clean up, the new `Preloader#grouped_records` relies on `AR::Associations::Association` knowing about both `reflection` and model's `klass`.

`AR::Base#association` now raises a descriptive error when trying to access non-existent associations. Previously it would blow up with a confusing `NoMethodError: undefined method 'association_class' for nil:NilClass`.

/cc @jonleighton @tenderlove