-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
After updating to Mongoid 4.0.0.beta1, my model with a field named 'invalid' results in a wrong number of arguments (1 for 0) error within the new creatable/updatable concerns.
In particular, the prepare_update/prepare_insert methods are dependent on the invalid?(context = nil) method from ActiveModel::Validations:
https://github.com/mongoid/mongoid/blob/master/lib/mongoid/persistable/updatable.rb#L113
def prepare_update(options = {}) return false if performing_validations?(options) && invalid?(:update) process_flagged_destroys result = run_callbacks(:save) do run_callbacks(:update) do yield(self) true end end post_process_persist(result, options) and result end
Because the field name is 'invalid', the 'invalid?' method has been redefined by:
https://github.com/mongoid/mongoid/blob/master/lib/mongoid/fields.rb#L475
# Create the check method for the provided field. # # @example Create the check. # Model.create_field_check("name", "name") # # @param [ String ] name The name of the attribute. # @param [ String ] meth The name of the method. # # @since 2.4.0 def create_field_check(name, meth) generated_methods.module_eval do re_define_method("#{meth}?") do attr = read_attribute(name) attr == true || attr.present? end end end
I'm submitting this to propose that 'invalid' be added to the Mongoid.destructive_fields list.