(results, metaData)
| 383 | } |
| 384 | |
| 385 | handleInsertQuery(results, metaData) { |
| 386 | if (this.instance) { |
| 387 | // add the inserted row id to the instance |
| 388 | const autoIncrementAttribute = this.model.autoIncrementAttribute; |
| 389 | let id = null; |
| 390 | let autoIncrementAttributeAlias = null; |
| 391 | |
| 392 | if (Object.prototype.hasOwnProperty.call(this.model.rawAttributes, autoIncrementAttribute) && |
| 393 | this.model.rawAttributes[autoIncrementAttribute].field !== undefined) |
| 394 | autoIncrementAttributeAlias = this.model.rawAttributes[autoIncrementAttribute].field; |
| 395 | |
| 396 | id = id || results && results[0][this.getInsertIdField()]; |
| 397 | id = id || metaData && metaData[this.getInsertIdField()]; |
| 398 | id = id || results && results[0][autoIncrementAttribute]; |
| 399 | id = id || autoIncrementAttributeAlias && results && results[0][autoIncrementAttributeAlias]; |
| 400 | |
| 401 | this.instance[autoIncrementAttribute] = id; |
| 402 | |
| 403 | if (this.instance.dataValues) { |
| 404 | for (const key in results[0]) { |
| 405 | if (Object.prototype.hasOwnProperty.call(results[0], key)) { |
| 406 | const record = results[0][key]; |
| 407 | |
| 408 | const attr = _.find(this.model.rawAttributes, attribute => attribute.fieldName === key || attribute.field === key); |
| 409 | |
| 410 | this.instance.dataValues[attr && attr.fieldName || key] = record; |
| 411 | } |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| 419 | module.exports = Query; |
no test coverage detected