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

Embedded_in does not set parent correctly before attempting to save

    • Type: Icon: Task Task
    • Resolution: Done
    • 2.3.4
    • Affects Version/s: None
    • Component/s: None

      We were trying to upgrade to Mongoid 2.2.0 and ran into the following bug. This behavior appears to have been introduced or refactored in 76d8692.

      We have a relatively simple embedded one-to-many relationship between two models. When you attempt to assign the parent model to the child model via child_instance.parent = parent_instance, this attempts to save the child model. However, it appears that bind_one is not properly setting the parent association to the child instance. This bug was exposed because we have a validation in the child model (which gets executed due to the base.save if persistable? call on line 25 of relations/embedded/in.rb) that references a property on the parent model, and the parent model is returning nil.

      I'll write a failing spec and submit a pull request to verify.

            Assignee:
            Unassigned Unassigned
            Reporter:
            ajsharp Alex Sharp
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: