@@ -67,9 +67,10 @@ module.exports =
67
67
return resourceConfig . table || underscore ( resourceConfig . name ) ;
68
68
}
69
69
70
- function filterQuery ( resourceConfig , params ) {
70
+ function filterQuery ( resourceConfig , params , options ) {
71
71
var table = getTable ( resourceConfig ) ;
72
- var query = this . query . select ( table + '.*' ) . from ( table ) ;
72
+ var query = options && options . transaction || this . query ;
73
+ query = query . select ( table + '.*' ) . from ( table ) ;
73
74
params = params || { } ;
74
75
params . where = params . where || { } ;
75
76
params . orderBy = params . orderBy || params . sort ;
@@ -378,7 +379,8 @@ module.exports =
378
379
var instance = undefined ;
379
380
options = options || { } ;
380
381
options [ 'with' ] = options [ 'with' ] || [ ] ;
381
- return this . query . select ( '*' ) . from ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . then ( function ( rows ) {
382
+ var query = options && options . transaction || this . query ;
383
+ return query . select ( '*' ) . from ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . then ( function ( rows ) {
382
384
if ( ! rows . length ) {
383
385
return DSUtils . Promise . reject ( new Error ( 'Not Found!' ) ) ;
384
386
} else {
@@ -410,7 +412,8 @@ module.exports =
410
412
var _this4 = this ;
411
413
412
414
attrs = DSUtils . removeCircular ( DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) ) ;
413
- return this . query ( getTable ( resourceConfig ) ) . insert ( attrs , resourceConfig . idAttribute ) . then ( function ( ids ) {
415
+ var query = options && options . transaction || this . query ;
416
+ return query ( getTable ( resourceConfig ) ) . insert ( attrs , resourceConfig . idAttribute ) . then ( function ( ids ) {
414
417
if ( attrs [ resourceConfig . idAttribute ] ) {
415
418
return _this4 . find ( resourceConfig , attrs [ resourceConfig . idAttribute ] , options ) ;
416
419
} else if ( ids . length ) {
@@ -426,7 +429,8 @@ module.exports =
426
429
var _this5 = this ;
427
430
428
431
attrs = DSUtils . removeCircular ( DSUtils . omit ( attrs , resourceConfig . relationFields || [ ] ) ) ;
429
- return this . query ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . update ( attrs ) . then ( function ( ) {
432
+ var query = options && options . transaction || this . query ;
433
+ return query ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . update ( attrs ) . then ( function ( ) {
430
434
return _this5 . find ( resourceConfig , id , options ) ;
431
435
} ) ;
432
436
}
@@ -452,8 +456,9 @@ module.exports =
452
456
}
453
457
} , {
454
458
key : 'destroy' ,
455
- value : function destroy ( resourceConfig , id ) {
456
- return this . query ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . del ( ) . then ( function ( ) {
459
+ value : function destroy ( resourceConfig , id , options ) {
460
+ var query = options && options . transaction || this . query ;
461
+ return query ( getTable ( resourceConfig ) ) . where ( resourceConfig . idAttribute , toString ( id ) ) . del ( ) . then ( function ( ) {
457
462
return undefined ;
458
463
} ) ;
459
464
}
0 commit comments