@@ -464,7 +464,8 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
464464 props = isUndefined ( _props ) ? props : _props
465465 const insertOpts = self . getOpt ( 'insertOpts' , opts )
466466 insertOpts . returnChanges = true
467- return self . selectTable ( mapper , opts ) . insert ( props , insertOpts ) . run ( self . getOpt ( 'runOpts' , opts ) )
467+ _props = withoutRelations ( mapper , props )
468+ return self . selectTable ( mapper , opts ) . insert ( _props , insertOpts ) . run ( self . getOpt ( 'runOpts' , opts ) )
468469 } ) . then ( function ( cursor ) {
469470 self . _handleErrors ( cursor )
470471 let record
@@ -525,15 +526,15 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
525526 return change . new_val
526527 } )
527528 }
528- let result = new Response ( records , cursor , 'createMany' )
529- result . created = records . length
530- result = self . getOpt ( 'raw' , opts ) ? result : result . data
529+ let response = new Response ( records , cursor , 'createMany' )
530+ response . created = records . length
531+ response = self . respond ( response , opts )
531532
532533 // afterCreateMany lifecycle hook
533534 op = opts . op = 'afterCreateMany'
534- return resolve ( self [ op ] ( mapper , props , opts , result ) ) . then ( function ( _result ) {
535+ return resolve ( self [ op ] ( mapper , props , opts , response ) ) . then ( function ( _response ) {
535536 // Allow for re-assignment from lifecycle hook
536- return isUndefined ( _result ) ? result : _result
537+ return isUndefined ( _response ) ? response : _response
537538 } )
538539 } )
539540 } ,
@@ -566,14 +567,14 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
566567 self . dbg ( op , id , opts )
567568 return self . selectTable ( mapper , opts ) . get ( id ) . delete ( self . getOpt ( 'deleteOpts' , opts ) ) . run ( self . getOpt ( 'runOpts' , opts ) )
568569 } ) . then ( function ( cursor ) {
569- let result = new Response ( undefined , cursor , 'destroy' )
570- result = self . getOpt ( 'raw' , opts ) ? result : undefined
570+ let response = new Response ( undefined , cursor , 'destroy' )
571+ response = self . respond ( response , opts )
571572
572573 // afterDestroy lifecycle hook
573574 op = opts . op = 'afterDestroy'
574- return resolve ( self [ op ] ( mapper , id , opts , result ) ) . then ( function ( _result ) {
575+ return resolve ( self [ op ] ( mapper , id , opts , response ) ) . then ( function ( _response ) {
575576 // Allow for re-assignment from lifecycle hook
576- return isUndefined ( _result ) ? result : _result
577+ return isUndefined ( _response ) ? response : _response
577578 } )
578579 } )
579580 } ,
@@ -618,14 +619,14 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
618619 . delete ( self . getOpt ( 'deleteOpts' , opts ) )
619620 . run ( self . getOpt ( 'runOpts' , opts ) )
620621 } ) . then ( function ( cursor ) {
621- let result = new Response ( undefined , cursor , 'destroyAll' )
622- result = self . getOpt ( 'raw' , opts ) ? result : undefined
622+ let response = new Response ( undefined , cursor , 'destroyAll' )
623+ response = self . respond ( response , opts )
623624
624625 // afterDestroyAll lifecycle hook
625626 op = opts . op = 'afterDestroyAll'
626- return resolve ( self [ op ] ( mapper , query , opts , result ) ) . then ( function ( _result ) {
627+ return resolve ( self [ op ] ( mapper , query , opts , response ) ) . then ( function ( _response ) {
627628 // Allow for re-assignment from lifecycle hook
628- return isUndefined ( _result ) ? result : _result
629+ return isUndefined ( _response ) ? response : _response
629630 } )
630631 } )
631632 } ,
@@ -726,15 +727,15 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
726727
727728 return Promise . all ( tasks )
728729 } ) . then ( function ( ) {
729- let result = new Response ( record , { } , 'find' )
730- result . found = record ? 1 : 0
731- result = self . getOpt ( 'raw' , opts ) ? result : result . data
730+ let response = new Response ( record , { } , 'find' )
731+ response . found = record ? 1 : 0
732+ response = self . respond ( response , opts )
732733
733734 // afterFind lifecycle hook
734735 op = opts . op = 'afterFind'
735- return resolve ( self [ op ] ( mapper , id , opts , result ) ) . then ( function ( _result ) {
736+ return resolve ( self [ op ] ( mapper , id , opts , response ) ) . then ( function ( _response ) {
736737 // Allow for re-assignment from lifecycle hook
737- return isUndefined ( _result ) ? result : _result
738+ return isUndefined ( _response ) ? response : _response
738739 } )
739740 } )
740741 } ,
@@ -866,15 +867,15 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
866867 return Promise . all ( tasks )
867868 } ) . then ( function ( ) {
868869 records || ( records = [ ] )
869- let result = new Response ( records , { } , 'findAll' )
870- result . found = records . length
871- result = self . getOpt ( 'raw' , opts ) ? result : result . data
870+ let response = new Response ( records , { } , 'findAll' )
871+ response . found = records . length
872+ response = self . respond ( response , opts )
872873
873874 // afterFindAll lifecycle hook
874875 op = opts . op = 'afterFindAll'
875- return resolve ( self [ op ] ( mapper , query , opts , result ) ) . then ( function ( _result ) {
876+ return resolve ( self [ op ] ( mapper , query , opts , response ) ) . then ( function ( _response ) {
876877 // Allow for re-assignment from lifecycle hook
877- return isUndefined ( _result ) ? result : _result
878+ return isUndefined ( _response ) ? response : _response
878879 } )
879880 } )
880881 } ,
@@ -937,15 +938,15 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
937938 } else {
938939 throw new Error ( 'Not Found' )
939940 }
940- let result = new Response ( record , cursor , 'update' )
941- result . updated = 1
942- result = self . getOpt ( 'raw' , opts ) ? result : result . data
941+ let response = new Response ( record , cursor , 'update' )
942+ response . updated = 1
943+ response = self . respond ( response , opts )
943944
944945 // afterUpdate lifecycle hook
945946 op = opts . op = 'afterUpdate'
946- return resolve ( self [ op ] ( mapper , id , props , opts , result ) ) . then ( function ( _result ) {
947+ return resolve ( self [ op ] ( mapper , id , props , opts , response ) ) . then ( function ( _response ) {
947948 // Allow for re-assignment from lifecycle hook
948- return isUndefined ( _result ) ? result : _result
949+ return isUndefined ( _response ) ? response : _response
949950 } )
950951 } )
951952 } ,
@@ -996,15 +997,15 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
996997 if ( cursor && cursor . changes && cursor . changes . length ) {
997998 records = cursor . changes . map ( function ( change ) { return change . new_val } )
998999 }
999- let result = new Response ( records , cursor , 'update' )
1000- result . updated = records . length
1001- result = self . getOpt ( 'raw' , opts ) ? result : result . data
1000+ let response = new Response ( records , cursor , 'update' )
1001+ response . updated = records . length
1002+ response = self . respond ( response , opts )
10021003
10031004 // afterUpdateAll lifecycle hook
10041005 op = opts . op = 'afterUpdateAll'
1005- return resolve ( self [ op ] ( mapper , props , query , opts , result ) ) . then ( function ( _result ) {
1006+ return resolve ( self [ op ] ( mapper , props , query , opts , response ) ) . then ( function ( _response ) {
10061007 // Allow for re-assignment from lifecycle hook
1007- return isUndefined ( _result ) ? result : _result
1008+ return isUndefined ( _response ) ? response : _response
10081009 } )
10091010 } )
10101011 } ,
@@ -1054,15 +1055,15 @@ addHiddenPropsToTarget(RethinkDBAdapter.prototype, {
10541055 if ( cursor && cursor . changes && cursor . changes . length ) {
10551056 updatedRecords = cursor . changes . map ( function ( change ) { return change . new_val } )
10561057 }
1057- let result = new Response ( updatedRecords || [ ] , cursor , 'update' )
1058- result . updated = result . data . length
1059- result = self . getOpt ( 'raw' , opts ) ? result : result . data
1058+ let response = new Response ( updatedRecords || [ ] , cursor , 'update' )
1059+ response . updated = response . data . length
1060+ response = self . respond ( response , opts )
10601061
10611062 // afterUpdateMany lifecycle hook
10621063 op = opts . op = 'afterUpdateMany'
1063- return resolve ( self [ op ] ( mapper , records , opts , result ) ) . then ( function ( _result ) {
1064+ return resolve ( self [ op ] ( mapper , records , opts , response ) ) . then ( function ( _response ) {
10641065 // Allow for re-assignment from lifecycle hook
1065- return isUndefined ( _result ) ? result : _result
1066+ return isUndefined ( _response ) ? response : _response
10661067 } )
10671068 } )
10681069 } ,
0 commit comments