-
Notifications
You must be signed in to change notification settings - Fork 57
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
NoMethodError: undefined method `cast' for nil:NilClass after set value to field #53
Comments
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 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.
The text was updated successfully, but these errors were encountered: