Uploaded image for project: 'Mongoid'
  1. Mongoid
  2. MONGOID-3710

Cloning an existing model containing a field which has since been removed results in error

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 5.0.2
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      lib/mongoid/copyable.rb#L24-25 clones a document to an attributes hash and constructs a new document with it. This will cause an error relating to dynamic attributes when the document to be cloned has a field present which has since been removed from the model definition.

      The desired behavior (I believe) would be either to ignore these extra attributes, or include them in the clone (as it is a clone of an existing document). Including the dynamic attribute behavior is not appropriate in this scenario.

      Additionally, there is no batch unset() operation provided by mongoid for use with migrations that might drop these unused fields.

      (Mongoid 4.0.0)

            Assignee:
            Unassigned Unassigned
            Reporter:
            tzar Tapio Saarinen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: