clio / polymorphic_integer_type

MIT License
37 stars 35 forks source link

Creating association using << sets type value as nil #17

Closed joekrump closed 10 months ago

joekrump commented 7 years ago

Ex.

Setup:

# config
PolymorphicIntegerType::Mapping.configuration do |config|
  config.add :subject, {
    1 => "Car"
  }
end

class Car < ActiveRecord
  include PolymorphicIntegerType::Extensions
  has_many :extra_things,
    as: :subject,
    integer_type: true,
    dependent: :destroy
end

class ExtraThing
  include PolymorphicIntegerType::Extensions

  belongs_to :subject, polymorphic: true, integer_type: true

end
car = Car.new(...)
car.save

a_fancy_new_thing = ExtraThing.new(...)

car.extra_things << a_fancy_new_thing
car.save

Result: subject_type on a_fancy_new_thing is nil not 1