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

Not saving nested_attributes for 'belongs_to' in a 1:1 relationship

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

      I have two model's Contact, and User. When I create a new user I am trying to create the contact at the same time. But It is not getting created for some reason. Any ideas on why?

      {{`}}ruby
      class Contact
      include Mongoid::Document
      include Mongoid::Timestamps
      include Mongoid::MultiParameterAttributes
      include Mongoid::Paranoia
      include Mongoid::Versioning

      1. Attr.
        attr_accessible :first_name, :last_name, :birthday, :email_addresses_attributes, :phone_numbers_attributes, :relationships_attributes, :addresses_attributes

      #Relationships
      belongs_to :firm, validate: true
      has_one :user # contact information for user
      has_many :relationships, autosave: true
      has_many :clients
      has_many :notes, dependent: :destroy
      ...
      end

      class User
      include Mongoid::Document
      include ActiveModel::SecurePassword
      include Mongoid::Timestamps

      1. Attr.
        attr_accessible :contact_id, :contact_attributes, :password, :password_confirmation, :google_tokens

      #Relationships
      belongs_to :firm, validate: true
      belongs_to :contact, validate: true, autosave: true
      has_one :user_type
      embeds_many :histories

      1. Nested Attrs
        accepts_nested_attributes_for :contact
        ...
        end

            Assignee:
            Unassigned Unassigned
            Reporter:
            jwaldrip Jason Waldrip
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: