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

has_and_belongs_to_many duplicate associations

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

      
      class Post
        include Mongoid::Document
        has_and_belongs_to_many :tags
      end
      
      class Tag
        include Mongoid::Document
        has_and_belongs_to_many :posts
      end
      
      Loading development environment (Rails 3.1.3)
      ruby-1.9.3-p0 :001 > t = Tag.create
       => #<Tag _id: 4eddc9d5148aaa3328000003, _type: nil, post_ids: []> 
      ruby-1.9.3-p0 :002 > t.posts.create
       => #<Post _id: 4eddc9db148aaa3328000004, _type: nil, tag_ids: [BSON::ObjectId('4eddc9d5148aaa3328000003')]> 
      ruby-1.9.3-p0 :003 > t
       => #<Tag _id: 4eddc9d5148aaa3328000003, _type: nil, post_ids: [BSON::ObjectId('4eddc9db148aaa3328000004')]> 
      ruby-1.9.3-p0 :004 > t.reload
       => #<Tag _id: 4eddc9d5148aaa3328000003, _type: nil, post_ids: [BSON::ObjectId('4eddc9db148aaa3328000004'), BSON::ObjectId('4eddc9db148aaa3328000004')]>
      
      

      When a new post is created for a tag, the post's id gets added to post_ids twice.

      using mongoid 2.3.4

      Can anyone replicate this?

            Assignee:
            Unassigned Unassigned
            Reporter:
            sausman Stephen Ausman
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: