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

Error when setting belong_to relation to BSON::ObjectId value

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

      Using Mongoid 3.1.0-stable (latest Github commit as of 2013-07-03, ref: 13f6a2dad15998206e30dc3ca6101b640c6ecd48)

      class Customer
        include Mongoid::Document
        belongs_to :sales_rep, class_name: 'User'
      end
      

      This works

      c = Customer.first
      c.sales_rep = User.first._id  # OK
      c.sales_rep = nil
      c.sales_rep = User.first._id  # OK
      

      This throws error

      c = Customer.first
      
      # first time
      c.sales_rep = User.first._id  # OK
      
      # second time
      c.sales_rep = User.first._id  
         #=> error undefined method `_id' for "51a36b546f2958eef0000053":Moped::BSON::ObjectId
      
      # third time
      c.sales_rep = User.first._id  # OK (strangely, running same method again works)
      

            Assignee:
            durran Durran Jordan
            Reporter:
            johnnyshields Johnny Shields
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: