@@ -201,14 +201,14 @@ Revision.setMethod(function compare(left, right) {
201
201
*
202
202
* @author Jelle De Loecker <jelle@elevenways.be>
203
203
* @since 0.0.1
204
- * @version 1.0.5
204
+ * @version 1.4.0
205
205
*/
206
206
Revision . setMethod ( function beforeSave ( record , options , creating ) {
207
207
208
- let main = record [ this . model . name ] ;
208
+ let main = record . $main ;
209
209
210
210
if ( ! main ) {
211
- throw new Error ( 'Unable to find main "' + this . model . name + '" data' ) ;
211
+ throw new Error ( 'Unable to find main "' + this . model . model_name + '" data' ) ;
212
212
}
213
213
214
214
// No revision to save when creating a record
@@ -221,14 +221,12 @@ Revision.setMethod(function beforeSave(record, options, creating) {
221
221
next = this . wait ( 'series' ) ;
222
222
223
223
// Find the original record
224
- Model . get ( that . model . name ) . findById ( main . _id , async function gotRecord ( err , result ) {
225
-
226
- var ori ;
224
+ Model . get ( this . model . model_name ) . findById ( record . $pk , async function gotRecord ( err , result ) {
227
225
228
226
if ( result ) {
229
227
230
228
// Get the original data
231
- ori = await that . model . convertRecordToDatasourceFormat ( result ) ;
229
+ let ori = await that . model . convertRecordToDatasourceFormat ( result ) ;
232
230
233
231
// Store the original data in a weakmap for later
234
232
revision_before . set ( options , ori ) ;
@@ -250,17 +248,11 @@ Revision.setMethod(function beforeSave(record, options, creating) {
250
248
*
251
249
* @author Jelle De Loecker <jelle@elevenways.be>
252
250
* @since 0.0.1
253
- * @version 1.1 .0
251
+ * @version 1.4 .0
254
252
*/
255
253
Revision . setMethod ( function afterSave ( record , options , created ) {
256
254
257
- var that = this ,
258
- earlier_data ,
259
- right ,
260
- main ,
261
- that ,
262
- left ,
263
- next ;
255
+ let earlier_data ;
264
256
265
257
if ( created ) {
266
258
earlier_data = { } ;
@@ -273,11 +265,12 @@ Revision.setMethod(function afterSave(record, options, created) {
273
265
return ;
274
266
}
275
267
276
- next = this . wait ( ) ;
277
- main = record [ that . model . name ] || record ;
268
+ let doc = this . model . createDocument ( record ) ;
269
+ let next = this . wait ( ) ;
270
+ const that = this ;
278
271
279
272
// Find the complete saved item
280
- Model . get ( that . model . name ) . findById ( main . _id , async function gotRecord ( err , result ) {
273
+ Model . get ( this . model . model_name ) . findByPk ( doc . $pk , async function gotRecord ( err , result ) {
281
274
282
275
if ( result ) {
283
276
@@ -287,8 +280,8 @@ Revision.setMethod(function afterSave(record, options, created) {
287
280
if ( new_data ) {
288
281
289
282
// Convert the objects so they can be diffed properly
290
- left = JSON . toDryObject ( earlier_data ) ;
291
- right = JSON . toDryObject ( new_data ) ;
283
+ let left = JSON . toDryObject ( earlier_data ) ,
284
+ right = JSON . toDryObject ( new_data ) ;
292
285
293
286
// Diff them
294
287
let delta = that . compare ( left , right ) ;
@@ -311,7 +304,7 @@ Revision.setMethod(function afterSave(record, options, created) {
311
304
312
305
// Add the delta information
313
306
revision_data = {
314
- [ that . revision_model . name ] : revision_data
307
+ [ that . revision_model . model_name ] : revision_data
315
308
} ;
316
309
317
310
// Save the data
0 commit comments