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

One sided many to many aren't updated when a referenced item is destroyed

    • Type: Icon: Task Task
    • Resolution: Done
    • 3.0.7
    • Affects Version/s: None
    • Component/s: None
    • None

      Hi.

      Here is the problem. Am I missing something ? Why is the array tag_ids not updated ?

      Unable to find source-code formatter for language: ruby```. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      
      #  example taken from http://mongoid.org/en/mongoid/docs/relations.html#has_and_belongs_to_many
      
      class Band
        include Mongoid::Document
        has_and_belongs_to_many :tags, inverse_of: nil
      end
      
      class Tag
        include Mongoid::Document
        field :name, type: String
      end
      
      tag1 = tag.create!
      tag2 = tag.create!
      
      band = Band.create!(tags: [tag1, tag2])
      puts band.tags.count == band.tag_ids.count # returns true
      
      tag1.destroy
      band.reload
      puts band.tags.count == band.tag_ids.count # returns false
      

            Assignee:
            durran Durran Jordan
            Reporter:
            abrisse abrisse
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: