-
Type: Bug
-
Resolution: Done
-
Priority: Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
I am updating a project to Mongoid 4 and experiencing a change in has_and_belongs_to_many behavior that I am not seeing in the docs.
When updating a relation with object.relation = [other_objects], I'm seeing the inverse relation get dropped.
This seems similar to MONGOID-3246
class Project include Mongoid::Document has_and_belongs_to_many :team_members end class TeamMember include Mongoid::Document field :name, type: String has_and_belongs_to_many :projects end project = Project.create() amy = TeamMember.create(name: 'amy') steve = TeamMember.create(name: 'steve') # Add Amy and Steve to the project project.team_members = [amy, steve] [project, amy, steve].each(&:reload) # Data looks good puts project.team_members.pluck(:name).inspect # => ['amy', 'steve'] puts amy.projects.count # => 1 puts steve.projects.count # => 1 # Remove Steve from the project, should just be Amy now project.team_members = [amy] [project, amy, steve].each(&:reload) # Amy has no projects now! puts project.team_members.pluck(:name).inspect # => ['amy'] puts amy.projects.count # => 0 Amy should still be on the project! Returns 1 in Mongoid 3 puts steve.projects.count # => 0
- duplicates
-
MONGOID-4273 Self-referencing has_and_belongs_to_many not updated properly
- Closed