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

Embedded fields should be persisted by atomic set()

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Critical - P2 Critical - P2
    • 6.0.0, 5.1.4
    • Affects Version/s: None
    • Component/s: None

      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!

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

              Created:
              Updated:
              Resolved: