Sha256: c3be475703000b0c5cd559c1f11cfef0c83c30797c9a739e0f8e0060bf0a432e
Contents?: true
Size: 911 Bytes
Versions: 18
Compression:
Stored size: 911 Bytes
Contents
# Bugfix: building an sti model from an association fails # https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/6306-collection-associations-build-method-not-supported-for-sti # https://github.com/rails/rails/issues/815 # https://github.com/rails/rails/pull/1686 ActiveRecord::Reflection::AssociationReflection.class_eval do def klass_with_sti(*opts) sti_col = klass.inheritance_column if (h = opts.first).is_a? Hash and (passed_type = ( h[sti_col] || h[sti_col.to_sym] )) and (new_klass = active_record.send(:compute_type, passed_type)) < klass new_klass else klass end end def build_association(*opts, &block) self.original_build_association_called = true klass_with_sti(*opts).new(*opts, &block) end def create_association(*opts, &block) self.original_build_association_called = true klass_with_sti(*opts).create(*opts, &block) end end
Version data entries
18 entries across 18 versions & 1 rubygems