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

HABTM relationship is not updated using #save

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

      Hi,

      I've got two models with a HABTM relationship:

      class Article
      include Mongoid::Document
      include Mongoid::Timestamps

      has_and_belongs_to_many :tags

      field :title, :type => String
      end

      and

      class Tag
      include Mongoid::Document
      include Mongoid::Timestamps

      has_and_belongs_to_many :articles
      end

      If I create a new article using #create everything works fine:

      Article.create(:title => "Test", :tag_id => Tag.first.id)

      But if I'm using #save, the tag model doesn't know anything about it related articles

      article = Article.new(:title => "Test", :tag_id => Tag.first.id)
      article.save

      I'm using Rails 3.1 and Mongoid 2.2.0. This bug does not exist in Mongoid 2.0.2.

            Assignee:
            Unassigned Unassigned
            Reporter:
            flippingbits flippingbits
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: