delete_one on embeds_many is callable and is not consistent with delete

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Fixed
    • Priority: Unknown
    • 9.0.0
    • Affects Version/s: 8.0.3
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • 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
              Reporter:
              Dmitry Rybakov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: