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

Model.inc and other atomic operators aren't using positional operators for embedded objects

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Closed
    • Resolution: Done
    • Affects Version/s: None
    • Fix Version/s: 3.1.0
    • Component/s: None
    • Labels:

      Description

       ruby
      require 'spec_helper'
       
      class Sandwich
        include Mongoid::Document
        embeds_many :slices
      end
       
      class Slice
        include Mongoid::Document
        field :position, default: 0
        include Mongoid::Document
        embedded_in :sandwiches
      end
       
      describe "relationship" do
        it "inc" do
          sandwich = Sandwich.create!
          slice = Slice.new
          sandwich.slices << slice
          Moped.logger = Logger.new(STDOUT)
          Moped.logger.level = Logger::DEBUG
          slice.inc :position, 5
        end
      end
      

      Executes this. Note slices.0.position.

        MOPED: 127.0.0.1:27017 UPDATE      
         database=mongoid_test collection=sandwiches selector={"_id"=>"510306c33b55524b26000001", "slices._id"=>"510306c33b55524b26000002"}
         update={"$inc"=>{"slices.0.position"=>5}} flags=[] (0.0811ms)
      

      Same goes for unset, set, etc., anything that calls query.update_all.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            dblock Daniel Doubrovkine
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: