@@ -80,12 +80,12 @@ SqlStore.prototype.populate = function(callback) {
80
80
self . baseModel . sync ( ) . asCallback ( cb ) ;
81
81
} ,
82
82
function ( cb ) {
83
- async . each ( self . relationArray , function ( model , ecb ) {
83
+ async . eachSeries ( self . relationArray , function ( model , ecb ) {
84
84
model . sync ( ) . asCallback ( ecb ) ;
85
85
} , cb ) ;
86
86
} ,
87
87
function ( cb ) {
88
- async . each ( self . resourceConfig . examples , function ( exampleJson , ecb ) {
88
+ async . eachSeries ( self . resourceConfig . examples , function ( exampleJson , ecb ) {
89
89
var validation = Joi . validate ( exampleJson , self . resourceConfig . attributes ) ;
90
90
if ( validation . error ) return ecb ( validation . error ) ;
91
91
self . create ( { request : { type : self . resourceConfig . resource } } , validation . value , ecb ) ;
@@ -225,6 +225,15 @@ SqlStore.prototype._fixObject = function(json) {
225
225
226
226
SqlStore . prototype . _errorHandler = function ( e , callback ) {
227
227
// console.log(e, e.stack);
228
+ if ( e . message . match ( / ^ E R _ L O C K _ D E A D L O C K / ) ) {
229
+ return callback ( {
230
+ status : "500" ,
231
+ code : "EMODIFIED" ,
232
+ title : "Resource Just Changed" ,
233
+ detail : "The resource you tried to mutate was modified by another request. Your request has been aborted."
234
+ } ) ;
235
+ }
236
+
228
237
return callback ( {
229
238
status : "500" ,
230
239
code : "EUNKNOWN" ,
@@ -321,7 +330,7 @@ SqlStore.prototype._dealWithTransaction = function(done, callback) {
321
330
} ) ;
322
331
} ;
323
332
var rollback = function ( e ) {
324
- debug ( "Err" , e ) ;
333
+ debug ( "Err" , transaction . name , e ) ;
325
334
var a = function ( ) {
326
335
if ( e instanceof Error ) return self . _errorHandler ( e , done ) ;
327
336
return done ( e ) ;
@@ -338,9 +347,12 @@ SqlStore.prototype._dealWithTransaction = function(done, callback) {
338
347
} ;
339
348
340
349
SqlStore . prototype . _clearAndSetMany = function ( relationModel , prop , theResource , keyName , ucKeyName , t , taskCallback ) {
341
- async . map ( theResource [ keyName ] || [ ] , function ( deadRow , acallback ) {
342
- deadRow . destroy ( t ) . asCallback ( acallback ) ;
343
- } , function ( deleteError ) {
350
+ var whereClause = { } ;
351
+ whereClause [ theResource . type + "Id" ] = theResource . id ;
352
+ relationModel . destroy ( {
353
+ where : whereClause ,
354
+ transaction : t . transaction
355
+ } ) . asCallback ( function ( deleteError ) {
344
356
if ( deleteError ) return taskCallback ( deleteError ) ;
345
357
346
358
async . map ( prop , function ( item , acallback ) {
@@ -354,7 +366,12 @@ SqlStore.prototype._clearAndSetMany = function(relationModel, prop, theResource,
354
366
} ;
355
367
356
368
SqlStore . prototype . _clearAndSetOne = function ( relationModel , prop , theResource , keyName , ucKeyName , t , taskCallback ) {
357
- var next = function ( deleteError ) {
369
+ var whereClause = { } ;
370
+ whereClause [ theResource . type + "Id" ] = theResource . id ;
371
+ relationModel . destroy ( {
372
+ where : whereClause ,
373
+ transaction : t . transaction
374
+ } ) . asCallback ( function ( deleteError ) {
358
375
if ( deleteError ) return taskCallback ( deleteError ) ;
359
376
if ( ! prop ) {
360
377
theResource [ "set" + ucKeyName ] ( null , t ) . asCallback ( taskCallback ) ;
@@ -365,12 +382,7 @@ SqlStore.prototype._clearAndSetOne = function(relationModel, prop, theResource,
365
382
theResource [ "set" + ucKeyName ] ( newRelationModel , t ) . asCallback ( taskCallback ) ;
366
383
} ) ;
367
384
}
368
- }
369
- if ( theResource [ keyName ] ) {
370
- theResource [ keyName ] . destroy ( t ) . asCallback ( next ) ;
371
- } else {
372
- next ( ) ;
373
- }
385
+ } ) ;
374
386
} ;
375
387
376
388
SqlStore . prototype . _clearAndSetRelationTables = function ( theResource , partialResource , t , callback ) {
0 commit comments