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

has_one child not being persisted when parent is persisted

    • Type: Icon: Task Task
    • Resolution: Done
    • 12_01_17
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      Hi.

      I'm using Mongoid 4.0.0 in a Rails 4.1.4 app.

      Your docs say the following for REFERENCED 1-1 relations:

      >Model#

      {name}

      =
      >Set the child document. If the parent document is persisted, then the child will be saved immediately. If setting to nil then the child will be deleted.

      Given I have, for example, the following models:

      class Parent
      include Mongoid::Document

      has_one :child
      end

      class Child
      include Mongoid::Document

      belongs_to :parent
      end

      If I do the following:

      p = Parent.new
      c = Child.new
      p.child = c
      p.save

      It only persists the Parent, not the Child, contradicting your documentation. Is this a bug?, or am I not clear about something?, or missing something?.

      Would appreciate your response.

      Best regards.

            Assignee:
            Unassigned Unassigned
            Reporter:
            luisincrespo luisincrespo
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: