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

delete_one on embeds_many is callable and is not consistent with delete

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 9.0.0
    • Affects Version/s: 8.0.3
    • Component/s: None
    • None

      The code below assumes that Post embeds many Comments:

      post = Post.create!
      10.times do |i|
        post.comments.create!
      end
      pp Post.collection.find().to_a.first['comments'].size # => 10
      post.comments.delete(post.comments.first)
      pp Post.collection.find().to_a.first['comments'].size # => 9
      post.comments.delete_one(post.comments.first)
      pp Post.collection.find().to_a.first['comments'].size # => 9
      

      So, there is a difference in the behaviour of delete (persists changes to the database), and delete_one (does not persist the changes).

      Further, there is delete_one method in the EmbedsMany::Proxy class; this method is private. However, it is not being called here; the method of Array extension is called instead.

      We should investigate the situation and either prohibit calling delete_one on associations, or document make them behave in accordance with delete, or document the difference.

            Assignee:
            jamis.buck@mongodb.com Jamis Buck
            Reporter:
            dmitry.rybakov@mongodb.com Dmitry Rybakov
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: