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

An embeds_one within 1-level deep should use a positional operator

    XMLWordPrintable

    Details

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

      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
        embeds_one :measure
      end
       
      class Measure
        include Mongoid::Document
        field :thickness
        embedded_in :slice
      end
       
      describe "relationship" do
        it "uses a positional operator" do
          sandwich = Sandwich.create!
          slice = Slice.new
          sandwich.slices << slice
          Moped.logger = Logger.new(STDOUT)
          Moped.logger.level = Logger::DEBUG
          slice.measure = Measure.new
        end
      end
      

        MOPED: 127.0.0.1:27017 UPDATE 
          database=mongoid_test 
          collection=sandwiches 
          selector={"_id"=>"510af81c3b55524e16000001", "slices._id"=>"510af81c3b55524e16000002"} 
          update={"$set"=>{"slices.0.measure"=>{"_id"=>"510af81c3b55524e16000003"}}} flags=[] 
      

      The Measure is embedded in Slice, which should behave just like any other field that can be set. This should be slices.$.measure for both $set and $unset.

        Attachments

          Activity

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: