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

delete_all referenced

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 6.1.1
    • Affects Version/s: None
    • Component/s: None
    • None

      (tested with latest 3.x and 4.x versions)

      delete_all does not load referenced document ids from strings like where does, the following:

      #!/usr/bin/env ruby
      require 'mongoid'
      DB_NAME = 'test_delete_all'
      class Band
        include Mongoid::Document
        has_many :members
      end
      class Member
        include Mongoid::Document
        field :name, type: String
        belongs_to :band
      end
      Mongoid.load_configuration(sessions: { default: { database: DB_NAME,
                                                        hosts:    ['localhost'],
                                                        options:  {} } })
      b = Band.create
      bid = b.id.to_s
      alice = b.members.create(name: 'alice')
      bob   = b.members.create(name: 'bob')
      
      puts "Band members count: #{Member.where(band_id: bid).count}"
      puts "Deleting: #{Member.delete_all(band_id: bid)}"
      

      produces:

      ruby test.rb
      Band members count: 2
      Deleting: 0
      

      Using Member.delete_all(band_id: Moped::BSON::ObjectId.from_string(bid)) works but that seems inconsistent with the behavior of where.

            Assignee:
            Unassigned Unassigned
            Reporter:
            raphael Raphaƫl Simon
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: