|
|
@ -161,7 +161,7 @@ abstract class BaseModel { |
|
|
|
const ids = (id + '').split('___'); |
|
|
|
const ids = (id + '').split('___'); |
|
|
|
const where = {}; |
|
|
|
const where = {}; |
|
|
|
for (let i = 0; i < this.pks.length; ++i) { |
|
|
|
for (let i = 0; i < this.pks.length; ++i) { |
|
|
|
where[this.pks[i].cn] = ids[i]; |
|
|
|
where[this.pks?.[i]?.cn] = ids[i]; |
|
|
|
} |
|
|
|
} |
|
|
|
return where; |
|
|
|
return where; |
|
|
|
} |
|
|
|
} |
|
|
@ -303,7 +303,7 @@ abstract class BaseModel { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const response = await this.dbDriver.batchInsert(this.tn, data, 50) |
|
|
|
const response = await this.dbDriver.batchInsert(this.tn, data, 50) |
|
|
|
.returning(this.pks[0].cn); |
|
|
|
.returning(this.pks?.[0]?.cn || '*'); |
|
|
|
|
|
|
|
|
|
|
|
await this.afterInsertb(data); |
|
|
|
await this.afterInsertb(data); |
|
|
|
|
|
|
|
|
|
|
@ -454,7 +454,7 @@ abstract class BaseModel { |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
async countByPk({where, condition}) { |
|
|
|
async countByPk({where, condition}) { |
|
|
|
try { |
|
|
|
try { |
|
|
|
return await this._run(this.$db.count(`${(this.pks[0] || this.columns[0]).cn} as count`) |
|
|
|
return await this._run(this.$db.count(`${(this.pks?.[0] || this.columns[0]).cn} as count`) |
|
|
|
.xwhere(where) |
|
|
|
.xwhere(where) |
|
|
|
.condition(condition) |
|
|
|
.condition(condition) |
|
|
|
.first()); |
|
|
|
.first()); |
|
|
@ -481,7 +481,7 @@ abstract class BaseModel { |
|
|
|
return await this._run(this.$db.where(this._whereFk({ |
|
|
|
return await this._run(this.$db.where(this._whereFk({ |
|
|
|
parentId, |
|
|
|
parentId, |
|
|
|
tnp |
|
|
|
tnp |
|
|
|
})).count(`${(this.pks[0] || this.columns[0]).cn} as count`) |
|
|
|
})).count(`${(this.pks?.[0] || this.columns[0]).cn} as count`) |
|
|
|
.xwhere(where) |
|
|
|
.xwhere(where) |
|
|
|
.condition(condition) |
|
|
|
.condition(condition) |
|
|
|
.first()); |
|
|
|
.first()); |
|
|
@ -722,7 +722,7 @@ abstract class BaseModel { |
|
|
|
const columns = [...(column_name ? [column_name] : []), ...fields.split(',').filter(Boolean)]; |
|
|
|
const columns = [...(column_name ? [column_name] : []), ...fields.split(',').filter(Boolean)]; |
|
|
|
const query = this.$db |
|
|
|
const query = this.$db |
|
|
|
.groupBy(columns) |
|
|
|
.groupBy(columns) |
|
|
|
.count(`${(this.pks[0] || this.columns[0]).cn} as count`) |
|
|
|
.count(`${(this.pks?.[0] || this.columns[0]).cn} as count`) |
|
|
|
.select(columns) |
|
|
|
.select(columns) |
|
|
|
.xhaving(having); |
|
|
|
.xhaving(having); |
|
|
|
|
|
|
|
|
|
|
@ -924,7 +924,7 @@ abstract class BaseModel { |
|
|
|
parent.map(p => { |
|
|
|
parent.map(p => { |
|
|
|
const query = this |
|
|
|
const query = this |
|
|
|
.dbDriver(child) |
|
|
|
.dbDriver(child) |
|
|
|
.where({[cn]: p[this.pks[0].cn]}) |
|
|
|
.where({[cn]: p[this.pks?.[0]?.cn]}) |
|
|
|
.xwhere(where).condition(condition) |
|
|
|
.xwhere(where).condition(condition) |
|
|
|
.select(...fields.split(',')); |
|
|
|
.select(...fields.split(',')); |
|
|
|
|
|
|
|
|
|
|
@ -935,7 +935,7 @@ abstract class BaseModel { |
|
|
|
|
|
|
|
|
|
|
|
const gs = _.groupBy(childs, cn); |
|
|
|
const gs = _.groupBy(childs, cn); |
|
|
|
parent.forEach(row => { |
|
|
|
parent.forEach(row => { |
|
|
|
row[child] = gs[row[this.pks[0].cn]] || []; |
|
|
|
row[child] = gs[row[this.pks?.[0]?.cn]] || []; |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -990,8 +990,8 @@ abstract class BaseModel { |
|
|
|
fields = fields || f || '*'; |
|
|
|
fields = fields || f || '*'; |
|
|
|
try { |
|
|
|
try { |
|
|
|
|
|
|
|
|
|
|
|
if (fields !== '*' && fields.split(',').indexOf(this.pks[0].cn) === -1) { |
|
|
|
if (fields !== '*' && fields.split(',').indexOf(this.pks?.[0]?.cn) === -1) { |
|
|
|
fields += ',' + this.pks[0].cn; |
|
|
|
fields += ',' + this.pks?.[0]?.cn; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const parent = await this.list({childs, where, fields, ...rest}); |
|
|
|
const parent = await this.list({childs, where, fields, ...rest}); |
|
|
|