rails/rails — Issue #4130: Use given type as class when bulding STI associations
Author: grosser
Created: 2011-12-22 12:00:31+00:00
State: open

e.g. when using nested attributes to build new associations they always have the wrong class without this patch
```Ruby
# Make build associations have their given type
# Makes that: user.persons.build(:type=>Manager).class == Manger
class ActiveRecord::Reflection::AssociationReflection
def build_association(*options)
if options.first.is_a?(Hash) and options.first[:type].presence
options.first[:type].to_s.constantize.new(*options)
else
klass.new(*options)
end
end
end
```