Open havran opened 7 years ago
I try refactor my code. Before model Page is inherited from base model ProjectItems (models shared same database table, but i want different fields in store on every model). Now i have common model settings in concern and problem with set value on fields disappear.
I am still curious with this but i think this is burried too deep for my knowledge :-/
Could you try reproduce the issue with a minimal app?
I have the same problem which present itself only when model inheritance is used and descendant defines it's own typed_store
. This has an unexpected effect of overriding typed_store
value for same store_attribute
for all class hierarchy and ancestors in particular.
For example this code results in all animals having gills:
class Animal < ApplicationRecord
typed_store :data do |d|
d.integer :ears_count, default: 2
end
end
class Fish < Animal
typed_store :data do |d|
d.boolean :has_gills, default: true
end
end
Animal.new.has_gills
# => true
Animal.new.ears_count
# NoMethodError: undefined method `ears_count'
Desired behaviour for me is this:
class Animal < ApplicationRecord
typed_store :data do |d|
d.integer :ears_count, default: 2
end
end
class Bear < Animal
end
class Fish < Animal
typed_store :data do |d|
d.boolean :has_gills, default: true
end
end
Animal.new.ears_count
# => 2
Animal.new.has_gills
# NoMethodError: undefined method `has_gills'
Bear.new.ears_count
# => 2
Bear.new.has_gills
# NoMethodError: undefined method `has_gills'
Fish.new.has_gills
# => true
Fish.new.ears_count
# NoMethodError: undefined method `ears_count'
There are one possible solution in previous commit. What are your thoughts?
Hello. Thanks for great gem!
I have weird problem in my production app.
If i try set value for field url in new or stored model, i always get NoMethodError: undefined method `cast' for nil:NilClass - but only for one field from all typed_Store defined fields.
Rails version is 5.x
In development mode works all ok.