Comparing version 0.4.2 to 0.4.3
@@ -1,4 +0,9 @@ | ||
0.4.2 / 2019-03-29 | ||
0.4.3 / 2019-05-09 | ||
================== | ||
* Fix: prevent Bone.dispatch from creating duplicated records of main table | ||
0.4.2 / 2019-04-26 | ||
================== | ||
* New: `Spell#orWhere()` and `Spell#orHaving()` | ||
@@ -5,0 +10,0 @@ * New: arithmetic operators |
@@ -758,33 +758,33 @@ 'use strict' | ||
static dispatch(spell, rows, fields) { | ||
if (Object.keys(spell.joins).length == 0) { | ||
return Collection.from(rows, row => this.instantiate(Object.values(row)[0])) | ||
} | ||
const results = new Collection() | ||
const { aliasName, table, primaryColumn, primaryKey } = this | ||
if (Object.keys(spell.joins).length == 0) { | ||
for (const row of rows) { | ||
results.push(this.instantiate(Object.values(row)[0])) | ||
for (const row of rows) { | ||
// If SQL contains subqueries, such as `SELECT * FROM (SELECT * FROM foo) AS bar`, | ||
// the table name of the columns in SQLite is the original table name instead of the alias. | ||
// Hence we need to fallback to original table name here. | ||
const main = row[aliasName] || row[table] | ||
let current = results.find(result => result[primaryKey] == main[primaryColumn]) | ||
if (!current) { | ||
current = this.instantiate(main) | ||
results.push(current) | ||
} | ||
} else { | ||
const { aliasName, table, primaryColumn, primaryKey } = this | ||
let current | ||
for (const row of rows) { | ||
// If SQL contains subqueries, such as `SELECT * FROM (SELECT * FROM foo) AS bar`, | ||
// the table name of the columns in SQLite is the original table name instead of the alias. | ||
// Hence we need to fallback to original table name here. | ||
const main = row[aliasName] || row[table] | ||
if (!current || current[primaryKey] != main[primaryColumn]) { | ||
current = this.instantiate(main) | ||
results.push(current) | ||
for (const qualifier in spell.joins) { | ||
const { Model, hasMany } = spell.joins[qualifier] | ||
// It seems mysql2 nests rows with table name instead of qualifier. | ||
const values = row[qualifier] || row[Model.table] | ||
const id = values[Model.primaryColumn] | ||
if (hasMany) { | ||
if (!current[qualifier]) current[qualifier] = new Collection() | ||
if (!id || current[qualifier].some(item => item[Model.primaryKey] == id)) continue | ||
current[qualifier].push(Model.instantiate(values)) | ||
} else { | ||
current[qualifier] = id ? Model.instantiate(values) : null | ||
} | ||
for (const qualifier in spell.joins) { | ||
const { Model, hasMany } = spell.joins[qualifier] | ||
// It seems mysql2 nests rows with table name instead of qualifier. | ||
const values = row[qualifier] || row[Model.table] | ||
const id = values[Model.primaryColumn] | ||
if (hasMany) { | ||
if (!current[qualifier]) current[qualifier] = new Collection() | ||
if (!id || current[qualifier].some(item => item[Model.primaryKey] == id)) continue | ||
current[qualifier].push(Model.instantiate(values)) | ||
} else { | ||
current[qualifier] = id ? Model.instantiate(values) : null | ||
} | ||
} | ||
} | ||
@@ -791,0 +791,0 @@ } |
{ | ||
"name": "leoric", | ||
"version": "0.4.2", | ||
"version": "0.4.3", | ||
"description": "JavaScript Object-relational mapping alchemy", | ||
"main": "index.js", | ||
"types": "index.d.ts", | ||
"files": [ | ||
"index.js", | ||
"index.d.ts", | ||
"lib" | ||
], | ||
"scripts": { | ||
@@ -8,0 +13,0 @@ "jsdoc": "rm -rf docs/api && jsdoc -c .jsdoc.json -d docs/api -t node_modules/@cara/minami", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
119989
12
3370