Reputation: 65
When I create instance of class, Error is raised NameError: undefined method 'options' for class 'Product'.
DB: MongoDB 3.6
Class Product
include Mongoid::Document
include Mongoid::Timestamps
include Mongoid::Attributes::Dynamic
field :options, type: Hash, default: {}
end
gem: mongoid (6.1.1)
NOTE: It works well when I change field name to option
or anything else, only options Fails. TIA
Upvotes: 0
Views: 934
Reputation: 2543
Taken from here:
Reserved names
If you define a field on your document that conflicts with a reserved method name in Mongoid, the configuration will raise an error. For a list of these you may look at Mongoid.destructive_fields.
Some code from mongoid:
# File 'lib/mongoid/config.rb', line 69
def destructive_fields
Composable.prohibited_methods
end
# File 'lib/mongoid/composable.rb', line 98
def prohibited_methods
@prohibited_methods ||= MODULES.flat_map do |mod|
mod.instance_methods.map(&:to_sym)
end
end
MODULES
constant contains Fields
module at least which defines options
method. Maybe it's the reason.
Upvotes: 2