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

N..N Not saving ID's for new records

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

      If i have an N..N relationship between Site and User when I do the following:

      @site.create 
      user = @site.users.new() 
      user.save 
      

      @site will end up with no user in site_ids.

      Here is an example that will produce the issue:

      class User
        include Mongoid::Document
        has_and_belongs_to_many :sites, :autosave => true
      end
      
      class Site
        include Mongoid::Document
        has_and_belongs_to_many :users, :autosave => true
      end
      
      @site= Site.create()
      @user= @site.users.new()
      @user.save
      
      @site= Site.last
      
      @site
      #<Site _id: 4e8cc21d390b7c802c000005, _type: nil, created_at: 2011-10-05 20:46:21 UTC, updated_at: 2011-10-05 20:46:21 UTC, user_ids: []>
      
      @user
      #<User _id: 4e8cc220390b7c802c000006, _type: nil, created_at: 2011-10-05 20:46:27 UTC, updated_at: 2011-10-05 20:46:27 UTC, site_ids: [BSON::ObjectId('4e8cc21d390b7c802c000005')] >
      

      (original google groups question: http://groups.google.com/group/mongoid/browse_thread/thread/8edb3ad41ecfcde4/b345ba016fe4cd44#b345ba016fe4cd44)

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

              Created:
              Updated:
              Resolved: