Only deleting relationships that needs to be deleted.
Executing relationship callbacks on deletion of relationship
This pull introduces/changes:
Respecting has_one constraint on relationships
User.has_many :snaps and Snap.has_one :useruser_1.snaps = [snap] and now if we do user_2.snaps = [snap] then the relationship between user_1 and snap will be deleted, earlier this relationship would be preserved and we would end up with two relationships from snap to user, which would violate Snap.has_one :user
Only deleting relationships that needs to be deleted.
Given User.has_many :snaps and user.snaps = [snap_1]. Now if we do user.snaps = [snap_1, snap_2] then the relationship between user and snap_1 would not be deleted. Earlier this would delete relationship between user and snap_1 and create again.
Executing relationship callbacks on deletion of relationship
User.has_many :snaps, dependent: :delete and user.snaps = [snap_1]. This dependent callback would be only executed when user is deleted. Now this callback would be executed when the relationship between user and snap_1 is also deleted. eg. user.snaps = [snap_2] would also delete snap_1.
Fixes :
Introduces :
This pull introduces/changes:
Respecting has_one constraint on relationships
User.has_many :snaps
andSnap.has_one :user
user_1.snaps = [snap]
and now if we douser_2.snaps = [snap]
then the relationship betweenuser_1
andsnap
will be deleted, earlier this relationship would be preserved and we would end up with two relationships from snap to user, which would violateSnap.has_one :user
Only deleting relationships that needs to be deleted. Given
User.has_many :snaps
anduser.snaps = [snap_1]
. Now if we douser.snaps = [snap_1, snap_2]
then the relationship betweenuser
andsnap_1
would not be deleted. Earlier this would delete relationship betweenuser
andsnap_1
and create again.Executing relationship callbacks on deletion of relationship
User.has_many :snaps, dependent: :delete
anduser.snaps = [snap_1]
. This dependent callback would be only executed whenuser
is deleted. Now this callback would be executed when the relationship betweenuser
andsnap_1
is also deleted. eg.user.snaps = [snap_2]
would also deletesnap_1
.