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

Embedded fields should be persisted by atomic set()

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Critical - P2
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 6.0.0, 5.1.4
    • Component/s: None
    • Labels:
    • Sprint:
      Ruby Sprint 39

      Description

      When the hash argument for set() contains embedded fields like fields declared by embeds_one, the field does not get persisted to db. (In fact, it is persisted to db and then rewrite as nil)

      This is what happens underneath:

      At this line, normal fields will be set on the object by write_attribute, which will not trigger db writes. Relationship fields will be created and persisted to db (reference).

      After each field is processed, only the relationship fields are persisted, and normal fields are only set on the object.

      At this line, field assignment are inserted in a hash named ops, which will be eventually used to persist all fields involved.

      This is where the relationship fields get missed, since the value of relationship fields are not inside attributes, therefore it gets a nil value instead, which caused the final data persisted on db to be nil.

      a PR is proposed:
      https://github.com/mongodb/mongoid/pull/4298

      Please take a look, thanks!

        Attachments

          Activity

            People

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            dongintercom Dong
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: