File tree 2 files changed +48
-0
lines changed
2 files changed +48
-0
lines changed Original file line number Diff line number Diff line change @@ -423,6 +423,10 @@ export default class Model extends StaticModel {
423
423
*/
424
424
425
425
delete ( ) {
426
+ if ( this . _customResource ) {
427
+ throw Error ( "The delete() method cannot be used in conjunction with the custom() method. Use for() instead." )
428
+ }
429
+
426
430
if ( ! this . hasId ( ) ) {
427
431
throw new Error ( 'This model has a empty ID.' )
428
432
}
@@ -436,6 +440,10 @@ export default class Model extends StaticModel {
436
440
}
437
441
438
442
save ( ) {
443
+ if ( this . _customResource ) {
444
+ throw Error ( "The save() method cannot be used in conjunction with the custom() method. Use for() instead." )
445
+ }
446
+
439
447
return this . hasId ( ) ? this . _update ( ) : this . _create ( )
440
448
}
441
449
@@ -472,6 +480,10 @@ export default class Model extends StaticModel {
472
480
*/
473
481
474
482
attach ( params ) {
483
+ if ( this . _customResource ) {
484
+ throw Error ( "The attach() method cannot be used in conjunction with the custom() method. Use for() instead." )
485
+ }
486
+
475
487
return this . request (
476
488
this . _reqConfig ( {
477
489
method : 'POST' ,
@@ -482,6 +494,10 @@ export default class Model extends StaticModel {
482
494
}
483
495
484
496
sync ( params ) {
497
+ if ( this . _customResource ) {
498
+ throw Error ( "The sync() method cannot be used in conjunction with the custom() method. Use for() instead." )
499
+ }
500
+
485
501
return this . request (
486
502
this . _reqConfig ( {
487
503
method : 'PUT' ,
Original file line number Diff line number Diff line change @@ -960,6 +960,38 @@ describe('Model methods', () => {
960
960
expect ( errorModel ) . toThrow ( 'Arguments to custom() must be strings or instances of Model.' )
961
961
} )
962
962
963
+ test ( 'it throws an error when CRUD and relationship operations are used in conjunction with custom()' , ( ) => {
964
+ errorModel = ( ) => {
965
+ const post = new Post ( { text : 'Hello' } ) . custom ( 'foo/bar' ) . save ( )
966
+ }
967
+
968
+ expect ( errorModel ) . toThrow ( "The save() method cannot be used in conjunction with the custom() method. Use for() instead." )
969
+
970
+ errorModel = ( ) => {
971
+ const post = new Post ( { id : 1 } ) . custom ( 'foo/bar' ) . delete ( )
972
+ }
973
+
974
+ expect ( errorModel ) . toThrow ( "The delete() method cannot be used in conjunction with the custom() method. Use for() instead." )
975
+
976
+ errorModel = ( ) => {
977
+ const post = new Post ( { id : 1 } )
978
+ const comment = post . comments ( ) . custom ( 'foo/bar' ) . attach ( {
979
+ text : 'Awesome post!'
980
+ } )
981
+ }
982
+
983
+ expect ( errorModel ) . toThrow ( "The attach() method cannot be used in conjunction with the custom() method. Use for() instead." )
984
+
985
+ errorModel = ( ) => {
986
+ const post = new Post ( { id : 1 } )
987
+ const comment = post . comments ( ) . custom ( 'foo/bar' ) . sync ( {
988
+ text : 'Awesome post!'
989
+ } )
990
+ }
991
+
992
+ expect ( errorModel ) . toThrow ( "The sync() method cannot be used in conjunction with the custom() method. Use for() instead." )
993
+ } )
994
+
963
995
test ( 'save() method makes a PUT request to the correct URL on nested object thas was fetched with find() method' , async ( ) => {
964
996
axiosMock . onGet ( 'http://localhost/posts/1/comments/1' ) . reply ( 200 , commentsResponse [ 0 ] )
965
997
axiosMock . onPut ( 'http://localhost/posts/1/comments/1' ) . reply ( 200 , commentsResponse [ 0 ] )
You can’t perform that action at this time.
0 commit comments