Ok, so I have the following models:

      class Agency
        include Mongoid::Document
        belongs_to :owner, class_name: 'User'
      end
      
      class User
        include Mongoid::Document
        include Mongoid::Timestamps
        embeds_one :agency_owner
      end
      
      class AgencyOwner
        include Mongoid::Document
        
        embedded_in :user
        belongs_to :agency
        
        validates_presence_of :agency
      end
      

      and then when I try to:

      agency.owner = some_user
      agency.save!
      
      # it does save just fine
      
      user.build_agency_owner agency: agency
      user.save!
      
      # *** error ***: 
      # user.reload.agency_owner is nil
      # even though the updated_at is refreshed
      

      however if instead of:

      agency.owner = some_user
      agency.save!
      

      I do:

      agency.owner_id = some_user.id
      agency.save!
      

      or

      agency.owner = some_user
      agency.save!
      
      some_user = User.find some_user.id
      
      user.build_agency_owner agency: agency
      user.save!
      

      it works.., so it is as if the some_user object gets somehow changed while interacting with the agency, so that it does not update anymore

      I'm using mongoid 4.0.0.beta1, and I hope that I'm not making a duplicate post.

      Thanks

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

              Created:
              Updated:
              Resolved: