This repository was archived by the owner on Apr 17, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change @@ -65,10 +65,14 @@ class KnormRelations {
65
65
const { name, references } = field ;
66
66
67
67
if ( references ) {
68
- const model = references . model . name ;
69
- delete this . _config . references [ model ] [ name ] ;
70
- if ( ! Object . keys ( this . _config . references [ model ] ) . length ) {
71
- delete this . _config . references [ model ] ;
68
+ if ( typeof references === 'function' ) {
69
+ delete this . _config . referenceFunctions [ name ] ;
70
+ } else {
71
+ const model = references . model . name ;
72
+ delete this . _config . references [ model ] [ name ] ;
73
+ if ( ! Object . keys ( this . _config . references [ model ] ) . length ) {
74
+ delete this . _config . references [ model ] ;
75
+ }
72
76
}
73
77
}
74
78
}
Original file line number Diff line number Diff line change @@ -218,7 +218,6 @@ describe('KnormRelations', () => {
218
218
Foo : { fooId : Quux . fields . fooId , fooId2 : Quux . fields . fooId2 }
219
219
} ) ;
220
220
} ) ;
221
- } ) ;
222
221
223
222
describe ( 'when a field is removed' , ( ) => {
224
223
it ( 'removes the field' , ( ) => {
@@ -249,6 +248,26 @@ describe('KnormRelations', () => {
249
248
Bar . removeField ( Bar . fields . barId ) ;
250
249
expect ( Bar . config . references , 'to be empty' ) ;
251
250
} ) ;
251
+
252
+ it ( "removes the field's reference function" , ( ) => {
253
+ class Foo extends Model { }
254
+ class Bar extends Model { }
255
+
256
+ Foo . fields = { id : { type : 'integer' } } ;
257
+ Bar . fields = {
258
+ id : 'integer' ,
259
+ fooId : {
260
+ type : 'integer' ,
261
+ references ( ) {
262
+ return Foo . fields . id ;
263
+ }
264
+ }
265
+ } ;
266
+
267
+ expect ( Bar . config . referenceFunctions , 'to have key' , 'fooId' ) ;
268
+ Bar . removeField ( Bar . fields . fooId ) ;
269
+ expect ( Bar . config . referenceFunctions , 'to be empty' ) ;
270
+ } ) ;
252
271
} ) ;
253
272
} ) ;
254
273
} ) ;
You can’t perform that action at this time.
0 commit comments