@@ -153,6 +153,30 @@ func TestDeleteWithAssociations(t *testing.T) {
153
153
}
154
154
}
155
155
156
+ func TestDeleteAssociationsWithUnscoped (t * testing.T ) {
157
+ user := GetUser ("unscoped_delete_with_associations" , Config {Account : true , Pets : 2 , Toys : 4 , Company : true , Manager : true , Team : 1 , Languages : 1 , Friends : 1 })
158
+
159
+ if err := DB .Create (user ).Error ; err != nil {
160
+ t .Fatalf ("failed to create user, got error %v" , err )
161
+ }
162
+
163
+ if err := DB .Unscoped ().Select (clause .Associations , "Pets.Toy" ).Delete (& user ).Error ; err != nil {
164
+ t .Fatalf ("failed to delete user, got error %v" , err )
165
+ }
166
+
167
+ for key , value := range map [string ]int64 {"Account" : 0 , "Pets" : 0 , "Toys" : 0 , "Company" : 1 , "Manager" : 1 , "Team" : 0 , "Languages" : 0 , "Friends" : 0 } {
168
+ if count := DB .Unscoped ().Model (& user ).Association (key ).Count (); count != value {
169
+ t .Errorf ("user's %v expects: %v, got %v" , key , value , count )
170
+ }
171
+ }
172
+
173
+ for key , value := range map [string ]int64 {"Account" : 0 , "Pets" : 0 , "Toys" : 0 , "Company" : 1 , "Manager" : 1 , "Team" : 0 , "Languages" : 0 , "Friends" : 0 } {
174
+ if count := DB .Model (& user ).Association (key ).Count (); count != value {
175
+ t .Errorf ("user's %v expects: %v, got %v" , key , value , count )
176
+ }
177
+ }
178
+ }
179
+
156
180
func TestDeleteSliceWithAssociations (t * testing.T ) {
157
181
users := []User {
158
182
* GetUser ("delete_slice_with_associations1" , Config {Account : true , Pets : 4 , Toys : 1 , Company : true , Manager : true , Team : 1 , Languages : 1 , Friends : 4 }),
0 commit comments