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

Updating polymorphic embed executes wrong query

    XMLWordPrintable

Details

    • Task
    • Status: Closed
    • Major - P3
    • Resolution: Gone away
    • None
    • 5.0.2
    • None

    Description

      Hi, I've got this document:

      class CourierJob
      include Mongoid::Document
      embeds_one :drop_address, as: :addressable, autobuild: true, class_name: "Addresses::ShipmentAddress"
      end

      now when i execute

      (:drop_address, some address object)

      on a CourierJob instance I can see the following in the rails logfile:

      MOPED: 127.0.0.1:27017 UPDATE database=project_test collection=courier_jobs selector=

      {"_id"=>BSON::ObjectId('537e0b50476f6c1b19190000')}

      update={"$set"=>{"address"=>

      {"_id"=>BSON::ObjectId('537e0b50476f6c1b191c0000'), "_type"=>"Addresses::ShipmentAddress", ....}

      }}

      The part i am worried about is

      ={"$set"=>{"address"=>

      because it should be

      ={"$set"=>{"drop_address"=>

      The address model looks like this:

      class Address
      include Mongoid::Document
      embedded_in :addressable, polymorphic: true
      end

      class ShipmentAddress < Address
      ...
      end

      Is there something I am doing wrong or is this a bug?

      PS: if i do

      .drop_address

      on the same object right after the

       it gives me the correct result. After a reload from the db the the value is again the one from before 

      update_attribute{{`}}

      Attachments

        Issue Links

          Activity

            People

              dianna.hohensee@mongodb.com Dianna Hohensee
              Goltergaul Goltergaul [X]
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: