lib/mongoid/fields.rb in mongoid-3.1.7 vs lib/mongoid/fields.rb in mongoid-4.0.0.alpha1

- old
+ new

@@ -23,19 +23,17 @@ self.pre_processed_defaults = [] self.post_processed_defaults = [] field( :_id, - default: ->{ Moped::BSON::ObjectId.new }, + default: ->{ BSON::ObjectId.new }, pre_processed: true, - type: Moped::BSON::ObjectId + type: BSON::ObjectId ) alias :id :_id alias :id= :_id= - - attr_protected(:id, :_id, :_type) if Mongoid.protect_sensitive_fields? end # Apply all default values to the document which are not procs. # # @example Apply all the non-proc defaults. @@ -262,17 +260,17 @@ def replace_field(name, type) remove_defaults(name) add_field(name, fields[name].options.merge(type: type)) end - # Convenience method for determining if we are using +Moped::BSON::ObjectIds+ as + # Convenience method for determining if we are using +BSON::ObjectIds+ as # our id. # # @example Does this class use object ids? # person.using_object_ids? # - # @return [ true, false ] If the class uses Moped::BSON::ObjectIds for the id. + # @return [ true, false ] If the class uses BSON::ObjectIds for the id. # # @since 1.0.0 def using_object_ids? fields["_id"].object_id_field? end @@ -432,14 +430,15 @@ # # @since 2.4.0 def create_field_setter(name, meth, field) generated_methods.module_eval do re_define_method("#{meth}=") do |value| - write_attribute(name, value) + val = write_attribute(name, value) if field.foreign_key? remove_ivar(field.metadata.name) end + val end end end # Create the check method for the provided field. @@ -470,12 +469,13 @@ # # @since 2.4.0 def create_translations_getter(name, meth) generated_methods.module_eval do re_define_method("#{meth}_translations") do - attributes[name] ||= {} + (attributes[name] ||= {}).with_indifferent_access end + alias_method :"#{meth}_t", :"#{meth}_translations" end end # Create the translation setter method for the provided field. # @@ -496,9 +496,10 @@ field.type.mongoize(_value) end end attributes[name] = value end + alias_method :"#{meth}_t=", :"#{meth}_translations=" end end # Include the field methods as a module, so they can be overridden. #