Sha256: 9b75e1f770b07952be3b7611fef01bb78f253a1e4e9cc23a4694bb9df8830629
Contents?: true
Size: 923 Bytes
Versions: 5
Compression:
Stored size: 923 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 sti_col and (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
5 entries across 5 versions & 1 rubygems