|
|
@ -391,7 +391,10 @@ class BaseModelSqlv2 { |
|
|
|
}); |
|
|
|
}); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(childTable.table_name); |
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(childTn); |
|
|
|
await childModel.selectObject({ qb }); |
|
|
|
await childModel.selectObject({ qb }); |
|
|
|
await this.applySortAndFilter({ table: childTable, where, qb, sort }); |
|
|
|
await this.applySortAndFilter({ table: childTable, where, qb, sort }); |
|
|
|
|
|
|
|
|
|
|
@ -404,7 +407,7 @@ class BaseModelSqlv2 { |
|
|
|
.select(this.dbDriver.raw('? as ??', [p, GROUP_COL])) |
|
|
|
.select(this.dbDriver.raw('? as ??', [p, GROUP_COL])) |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
chilCol.column_name, |
|
|
|
chilCol.column_name, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(parentCol.column_name) |
|
|
|
.select(parentCol.column_name) |
|
|
|
// .where(parentTable.primaryKey.cn, p)
|
|
|
|
// .where(parentTable.primaryKey.cn, p)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, p)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, p)) |
|
|
@ -477,13 +480,16 @@ class BaseModelSqlv2 { |
|
|
|
const parentTable = await parentCol.getModel(); |
|
|
|
const parentTable = await parentCol.getModel(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
const children = await this.dbDriver.unionAll( |
|
|
|
const children = await this.dbDriver.unionAll( |
|
|
|
ids.map((p) => { |
|
|
|
ids.map((p) => { |
|
|
|
const query = this.dbDriver(childTable.table_name) |
|
|
|
const query = this.dbDriver(childTn) |
|
|
|
.count(`${chilCol?.column_name} as count`) |
|
|
|
.count(`${chilCol?.column_name} as count`) |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
chilCol.column_name, |
|
|
|
chilCol.column_name, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(parentCol.column_name) |
|
|
|
.select(parentCol.column_name) |
|
|
|
// .where(parentTable.primaryKey.cn, p)
|
|
|
|
// .where(parentTable.primaryKey.cn, p)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, p)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, p)) |
|
|
@ -525,12 +531,15 @@ class BaseModelSqlv2 { |
|
|
|
}); |
|
|
|
}); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(childTable.table_name); |
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(childTn); |
|
|
|
await this.applySortAndFilter({ table: childTable, where, qb, sort }); |
|
|
|
await this.applySortAndFilter({ table: childTable, where, qb, sort }); |
|
|
|
|
|
|
|
|
|
|
|
qb.whereIn( |
|
|
|
qb.whereIn( |
|
|
|
chilCol.column_name, |
|
|
|
chilCol.column_name, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(parentCol.column_name) |
|
|
|
.select(parentCol.column_name) |
|
|
|
// .where(parentTable.primaryKey.cn, p)
|
|
|
|
// .where(parentTable.primaryKey.cn, p)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, id)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, id)) |
|
|
@ -576,11 +585,14 @@ class BaseModelSqlv2 { |
|
|
|
const parentTable = await parentCol.getModel(); |
|
|
|
const parentTable = await parentCol.getModel(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const query = this.dbDriver(childTable.table_name) |
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const query = this.dbDriver(childTn) |
|
|
|
.count(`${chilCol?.column_name} as count`) |
|
|
|
.count(`${chilCol?.column_name} as count`) |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
chilCol.column_name, |
|
|
|
chilCol.column_name, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(parentCol.column_name) |
|
|
|
.select(parentCol.column_name) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, id)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, id)) |
|
|
|
) |
|
|
|
) |
|
|
@ -607,7 +619,8 @@ class BaseModelSqlv2 { |
|
|
|
|
|
|
|
|
|
|
|
// const tn = this.model.tn;
|
|
|
|
// const tn = this.model.tn;
|
|
|
|
// const cn = (await relColOptions.getChildColumn()).title;
|
|
|
|
// const cn = (await relColOptions.getChildColumn()).title;
|
|
|
|
const vtn = (await relColOptions.getMMModel()).table_name; |
|
|
|
const mmTable = await relColOptions.getMMModel(); |
|
|
|
|
|
|
|
const vtn = this.getTnPath(mmTable); |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
@ -619,7 +632,11 @@ class BaseModelSqlv2 { |
|
|
|
dbDriver: this.dbDriver, |
|
|
|
dbDriver: this.dbDriver, |
|
|
|
model: childTable, |
|
|
|
model: childTable, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const rtn = childTable.table_name; |
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rtn = childTn; |
|
|
|
const rtnId = childTable.id; |
|
|
|
const rtnId = childTable.id; |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(rtn).join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`); |
|
|
|
const qb = this.dbDriver(rtn).join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`); |
|
|
@ -634,7 +651,7 @@ class BaseModelSqlv2 { |
|
|
|
.clone() |
|
|
|
.clone() |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(cn) |
|
|
|
.select(cn) |
|
|
|
// .where(parentTable.primaryKey.cn, id)
|
|
|
|
// .where(parentTable.primaryKey.cn, id)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, id)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, id)) |
|
|
@ -680,7 +697,8 @@ class BaseModelSqlv2 { |
|
|
|
|
|
|
|
|
|
|
|
// const tn = this.model.tn;
|
|
|
|
// const tn = this.model.tn;
|
|
|
|
// const cn = (await relColOptions.getChildColumn()).title;
|
|
|
|
// const cn = (await relColOptions.getChildColumn()).title;
|
|
|
|
const vtn = (await relColOptions.getMMModel()).table_name; |
|
|
|
const mmTable = await relColOptions.getMMModel(); |
|
|
|
|
|
|
|
const vtn = this.getTnPath(mmTable); |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
@ -692,14 +710,18 @@ class BaseModelSqlv2 { |
|
|
|
dbDriver: this.dbDriver, |
|
|
|
dbDriver: this.dbDriver, |
|
|
|
model: childTable, |
|
|
|
model: childTable, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const rtn = childTable.table_name; |
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rtn = childTn; |
|
|
|
const rtnId = childTable.id; |
|
|
|
const rtnId = childTable.id; |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
.join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`) |
|
|
|
.join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`) |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(cn) |
|
|
|
.select(cn) |
|
|
|
// .where(parentTable.primaryKey.cn, id)
|
|
|
|
// .where(parentTable.primaryKey.cn, id)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, parentId)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, parentId)) |
|
|
@ -731,16 +753,21 @@ class BaseModelSqlv2 { |
|
|
|
const relColOptions = |
|
|
|
const relColOptions = |
|
|
|
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
|
|
|
|
|
|
|
|
const vtn = (await relColOptions.getMMModel()).table_name; |
|
|
|
const mmTable = await relColOptions.getMMModel(); |
|
|
|
|
|
|
|
const vtn = this.getTnPath(mmTable); |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
|
const cn = (await relColOptions.getChildColumn()).column_name; |
|
|
|
const cn = (await relColOptions.getChildColumn()).column_name; |
|
|
|
const childTable = await (await relColOptions.getParentColumn()).getModel(); |
|
|
|
const childTable = await (await relColOptions.getParentColumn()).getModel(); |
|
|
|
const rtn = childTable.table_name; |
|
|
|
|
|
|
|
const parentTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
const parentTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rtn = childTn; |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
.join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`) |
|
|
|
.join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`) |
|
|
|
// .select({
|
|
|
|
// .select({
|
|
|
@ -755,7 +782,7 @@ class BaseModelSqlv2 { |
|
|
|
.clone() |
|
|
|
.clone() |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(cn) |
|
|
|
.select(cn) |
|
|
|
// .where(parentTable.primaryKey.cn, id)
|
|
|
|
// .where(parentTable.primaryKey.cn, id)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, id)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, id)) |
|
|
@ -778,16 +805,21 @@ class BaseModelSqlv2 { |
|
|
|
const relColOptions = |
|
|
|
const relColOptions = |
|
|
|
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
|
|
|
|
|
|
|
|
const vtn = (await relColOptions.getMMModel()).table_name; |
|
|
|
const mmTable = await relColOptions.getMMModel(); |
|
|
|
|
|
|
|
const vtn = this.getTnPath(mmTable); |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
|
const cn = (await relColOptions.getChildColumn()).column_name; |
|
|
|
const cn = (await relColOptions.getChildColumn()).column_name; |
|
|
|
const childTable = await (await relColOptions.getParentColumn()).getModel(); |
|
|
|
const childTable = await (await relColOptions.getParentColumn()).getModel(); |
|
|
|
const rtn = childTable.table_name; |
|
|
|
|
|
|
|
const parentTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
const parentTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rtn = childTn; |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
.join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`) |
|
|
|
.join(vtn, `${vtn}.${vrcn}`, `${rtn}.${rcn}`) |
|
|
|
// .select({
|
|
|
|
// .select({
|
|
|
@ -796,7 +828,7 @@ class BaseModelSqlv2 { |
|
|
|
.count(`${vtn}.${vcn}`, { as: 'count' }) |
|
|
|
.count(`${vtn}.${vcn}`, { as: 'count' }) |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(cn) |
|
|
|
.select(cn) |
|
|
|
// .where(parentTable.primaryKey.cn, id)
|
|
|
|
// .where(parentTable.primaryKey.cn, id)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, parentId)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, parentId)) |
|
|
@ -820,7 +852,8 @@ class BaseModelSqlv2 { |
|
|
|
const relColOptions = |
|
|
|
const relColOptions = |
|
|
|
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
|
|
|
|
|
|
|
|
const vtn = (await relColOptions.getMMModel()).table_name; |
|
|
|
const mmTable = await relColOptions.getMMModel(); |
|
|
|
|
|
|
|
const vtn = this.getTnPath(mmTable); |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
@ -828,7 +861,11 @@ class BaseModelSqlv2 { |
|
|
|
const childTable = await (await relColOptions.getParentColumn()).getModel(); |
|
|
|
const childTable = await (await relColOptions.getParentColumn()).getModel(); |
|
|
|
const parentTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
const parentTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
const rtn = childTable.table_name; |
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rtn = childTn; |
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
.count(`*`, { as: 'count' }) |
|
|
|
.count(`*`, { as: 'count' }) |
|
|
|
.where((qb) => { |
|
|
|
.where((qb) => { |
|
|
@ -839,7 +876,7 @@ class BaseModelSqlv2 { |
|
|
|
.join(vtn, `${rtn}.${rcn}`, `${vtn}.${vrcn}`) |
|
|
|
.join(vtn, `${rtn}.${rcn}`, `${vtn}.${vrcn}`) |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(cn) |
|
|
|
.select(cn) |
|
|
|
// .where(parentTable.primaryKey.cn, pid)
|
|
|
|
// .where(parentTable.primaryKey.cn, pid)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, pid)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, pid)) |
|
|
@ -866,7 +903,8 @@ class BaseModelSqlv2 { |
|
|
|
const relColOptions = |
|
|
|
const relColOptions = |
|
|
|
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
(await relColumn.getColOptions()) as LinkToAnotherRecordColumn; |
|
|
|
|
|
|
|
|
|
|
|
const vtn = (await relColOptions.getMMModel()).table_name; |
|
|
|
const mmTable = await relColOptions.getMMModel(); |
|
|
|
|
|
|
|
const vtn = this.getTnPath(mmTable); |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vcn = (await relColOptions.getMMChildColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const vrcn = (await relColOptions.getMMParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
|
const rcn = (await relColOptions.getParentColumn()).column_name; |
|
|
@ -878,7 +916,11 @@ class BaseModelSqlv2 { |
|
|
|
}); |
|
|
|
}); |
|
|
|
const parentTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
const parentTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
const rtn = childTable.table_name; |
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rtn = childTn; |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(rtn).where((qb) => |
|
|
|
const qb = this.dbDriver(rtn).where((qb) => |
|
|
|
qb |
|
|
|
qb |
|
|
@ -889,7 +931,7 @@ class BaseModelSqlv2 { |
|
|
|
.join(vtn, `${rtn}.${rcn}`, `${vtn}.${vrcn}`) |
|
|
|
.join(vtn, `${rtn}.${rcn}`, `${vtn}.${vrcn}`) |
|
|
|
.whereIn( |
|
|
|
.whereIn( |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
`${vtn}.${vcn}`, |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(cn) |
|
|
|
.select(cn) |
|
|
|
// .where(parentTable.primaryKey.cn, pid)
|
|
|
|
// .where(parentTable.primaryKey.cn, pid)
|
|
|
|
.where(_wherePk(parentTable.primaryKeys, pid)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, pid)) |
|
|
@ -945,8 +987,12 @@ class BaseModelSqlv2 { |
|
|
|
const parentTable = await ( |
|
|
|
const parentTable = await ( |
|
|
|
await relColOptions.getParentColumn() |
|
|
|
await relColOptions.getParentColumn() |
|
|
|
).getModel(); |
|
|
|
).getModel(); |
|
|
|
const tn = childTable.table_name; |
|
|
|
|
|
|
|
const rtn = parentTable.table_name; |
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tn = childTn; |
|
|
|
|
|
|
|
const rtn = parentTn; |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(tn) |
|
|
|
const qb = this.dbDriver(tn) |
|
|
@ -993,8 +1039,11 @@ class BaseModelSqlv2 { |
|
|
|
}); |
|
|
|
}); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const tn = childTable.table_name; |
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
const rtn = parentTable.table_name; |
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const tn = childTn; |
|
|
|
|
|
|
|
const rtn = parentTn; |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(tn).where((qb) => { |
|
|
|
const qb = this.dbDriver(tn).where((qb) => { |
|
|
|
qb.whereNotIn( |
|
|
|
qb.whereNotIn( |
|
|
@ -1054,8 +1103,11 @@ class BaseModelSqlv2 { |
|
|
|
const cn = (await relColOptions.getChildColumn()).column_name; |
|
|
|
const cn = (await relColOptions.getChildColumn()).column_name; |
|
|
|
const childTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
const childTable = await (await relColOptions.getChildColumn()).getModel(); |
|
|
|
|
|
|
|
|
|
|
|
const rtn = parentTable.table_name; |
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
const tn = childTable.table_name; |
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rtn = parentTn; |
|
|
|
|
|
|
|
const tn = childTn; |
|
|
|
await childTable.getColumns(); |
|
|
|
await childTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(rtn) |
|
|
|
const qb = this.dbDriver(rtn) |
|
|
@ -1100,8 +1152,12 @@ class BaseModelSqlv2 { |
|
|
|
dbDriver: this.dbDriver, |
|
|
|
dbDriver: this.dbDriver, |
|
|
|
model: parentTable, |
|
|
|
model: parentTable, |
|
|
|
}); |
|
|
|
}); |
|
|
|
const rtn = parentTable.table_name; |
|
|
|
|
|
|
|
const tn = childTable.table_name; |
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const rtn = parentTn; |
|
|
|
|
|
|
|
const tn = childTn; |
|
|
|
await childTable.getColumns(); |
|
|
|
await childTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
const qb = this.dbDriver(rtn).where((qb) => { |
|
|
|
const qb = this.dbDriver(rtn).where((qb) => { |
|
|
@ -1569,15 +1625,19 @@ class BaseModelSqlv2 { |
|
|
|
return _wherePk(this.model.primaryKeys, id); |
|
|
|
return _wherePk(this.model.primaryKeys, id); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public get tnPath() { |
|
|
|
private getTnPath(tb: Model) { |
|
|
|
const schema = (this.dbDriver as any).searchPath?.(); |
|
|
|
const schema = (this.dbDriver as any).searchPath?.(); |
|
|
|
const table = |
|
|
|
const table = |
|
|
|
this.isMssql && schema |
|
|
|
this.isMssql && schema |
|
|
|
? this.dbDriver.raw('??.??', [schema, this.model.table_name]) |
|
|
|
? this.dbDriver.raw('??.??', [schema, tb.table_name]) |
|
|
|
: this.model.table_name; |
|
|
|
: tb.table_name; |
|
|
|
return table; |
|
|
|
return table; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public get tnPath() { |
|
|
|
|
|
|
|
return this.getTnPath(this.model); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get isSqlite() { |
|
|
|
get isSqlite() { |
|
|
|
return this.clientType === 'sqlite3'; |
|
|
|
return this.clientType === 'sqlite3'; |
|
|
|
} |
|
|
|
} |
|
|
@ -2230,6 +2290,9 @@ class BaseModelSqlv2 { |
|
|
|
await childTable.getColumns(); |
|
|
|
await childTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
switch (colOptions.type) { |
|
|
|
switch (colOptions.type) { |
|
|
|
case RelationTypes.MANY_TO_MANY: |
|
|
|
case RelationTypes.MANY_TO_MANY: |
|
|
|
{ |
|
|
|
{ |
|
|
@ -2237,12 +2300,14 @@ class BaseModelSqlv2 { |
|
|
|
const vParentCol = await colOptions.getMMParentColumn(); |
|
|
|
const vParentCol = await colOptions.getMMParentColumn(); |
|
|
|
const vTable = await colOptions.getMMModel(); |
|
|
|
const vTable = await colOptions.getMMModel(); |
|
|
|
|
|
|
|
|
|
|
|
await this.dbDriver(vTable.table_name).insert({ |
|
|
|
const vTn = this.getTnPath(vTable); |
|
|
|
[vParentCol.column_name]: this.dbDriver(parentTable.table_name) |
|
|
|
|
|
|
|
|
|
|
|
await this.dbDriver(vTn).insert({ |
|
|
|
|
|
|
|
[vParentCol.column_name]: this.dbDriver(parentTn) |
|
|
|
.select(parentColumn.column_name) |
|
|
|
.select(parentColumn.column_name) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, childId)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, childId)) |
|
|
|
.first(), |
|
|
|
.first(), |
|
|
|
[vChildCol.column_name]: this.dbDriver(childTable.table_name) |
|
|
|
[vChildCol.column_name]: this.dbDriver(childTn) |
|
|
|
.select(childColumn.column_name) |
|
|
|
.select(childColumn.column_name) |
|
|
|
.where(_wherePk(childTable.primaryKeys, rowId)) |
|
|
|
.where(_wherePk(childTable.primaryKeys, rowId)) |
|
|
|
.first(), |
|
|
|
.first(), |
|
|
@ -2251,10 +2316,10 @@ class BaseModelSqlv2 { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case RelationTypes.HAS_MANY: |
|
|
|
case RelationTypes.HAS_MANY: |
|
|
|
{ |
|
|
|
{ |
|
|
|
await this.dbDriver(childTable.table_name) |
|
|
|
await this.dbDriver(childTn) |
|
|
|
.update({ |
|
|
|
.update({ |
|
|
|
[childColumn.column_name]: this.dbDriver.from( |
|
|
|
[childColumn.column_name]: this.dbDriver.from( |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(parentColumn.column_name) |
|
|
|
.select(parentColumn.column_name) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, rowId)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, rowId)) |
|
|
|
.first() |
|
|
|
.first() |
|
|
@ -2266,10 +2331,10 @@ class BaseModelSqlv2 { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case RelationTypes.BELONGS_TO: |
|
|
|
case RelationTypes.BELONGS_TO: |
|
|
|
{ |
|
|
|
{ |
|
|
|
await this.dbDriver(childTable.table_name) |
|
|
|
await this.dbDriver(childTn) |
|
|
|
.update({ |
|
|
|
.update({ |
|
|
|
[childColumn.column_name]: this.dbDriver.from( |
|
|
|
[childColumn.column_name]: this.dbDriver.from( |
|
|
|
this.dbDriver(parentTable.table_name) |
|
|
|
this.dbDriver(parentTn) |
|
|
|
.select(parentColumn.column_name) |
|
|
|
.select(parentColumn.column_name) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, childId)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, childId)) |
|
|
|
.first() |
|
|
|
.first() |
|
|
@ -2325,6 +2390,9 @@ class BaseModelSqlv2 { |
|
|
|
await childTable.getColumns(); |
|
|
|
await childTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
await parentTable.getColumns(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const childTn = this.getTnPath(childTable); |
|
|
|
|
|
|
|
const parentTn = this.getTnPath(parentTable); |
|
|
|
|
|
|
|
|
|
|
|
switch (colOptions.type) { |
|
|
|
switch (colOptions.type) { |
|
|
|
case RelationTypes.MANY_TO_MANY: |
|
|
|
case RelationTypes.MANY_TO_MANY: |
|
|
|
{ |
|
|
|
{ |
|
|
@ -2332,13 +2400,15 @@ class BaseModelSqlv2 { |
|
|
|
const vParentCol = await colOptions.getMMParentColumn(); |
|
|
|
const vParentCol = await colOptions.getMMParentColumn(); |
|
|
|
const vTable = await colOptions.getMMModel(); |
|
|
|
const vTable = await colOptions.getMMModel(); |
|
|
|
|
|
|
|
|
|
|
|
await this.dbDriver(vTable.table_name) |
|
|
|
const vTn = this.getTnPath(vTable); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await this.dbDriver(vTn) |
|
|
|
.where({ |
|
|
|
.where({ |
|
|
|
[vParentCol.column_name]: this.dbDriver(parentTable.table_name) |
|
|
|
[vParentCol.column_name]: this.dbDriver(parentTn) |
|
|
|
.select(parentColumn.column_name) |
|
|
|
.select(parentColumn.column_name) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, childId)) |
|
|
|
.where(_wherePk(parentTable.primaryKeys, childId)) |
|
|
|
.first(), |
|
|
|
.first(), |
|
|
|
[vChildCol.column_name]: this.dbDriver(childTable.table_name) |
|
|
|
[vChildCol.column_name]: this.dbDriver(childTn) |
|
|
|
.select(childColumn.column_name) |
|
|
|
.select(childColumn.column_name) |
|
|
|
.where(_wherePk(childTable.primaryKeys, rowId)) |
|
|
|
.where(_wherePk(childTable.primaryKeys, rowId)) |
|
|
|
.first(), |
|
|
|
.first(), |
|
|
@ -2348,7 +2418,7 @@ class BaseModelSqlv2 { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case RelationTypes.HAS_MANY: |
|
|
|
case RelationTypes.HAS_MANY: |
|
|
|
{ |
|
|
|
{ |
|
|
|
await this.dbDriver(childTable.table_name) |
|
|
|
await this.dbDriver(childTn) |
|
|
|
// .where({
|
|
|
|
// .where({
|
|
|
|
// [childColumn.cn]: this.dbDriver(parentTable.tn)
|
|
|
|
// [childColumn.cn]: this.dbDriver(parentTable.tn)
|
|
|
|
// .select(parentColumn.cn)
|
|
|
|
// .select(parentColumn.cn)
|
|
|
@ -2361,7 +2431,7 @@ class BaseModelSqlv2 { |
|
|
|
break; |
|
|
|
break; |
|
|
|
case RelationTypes.BELONGS_TO: |
|
|
|
case RelationTypes.BELONGS_TO: |
|
|
|
{ |
|
|
|
{ |
|
|
|
await this.dbDriver(childTable.table_name) |
|
|
|
await this.dbDriver(childTn) |
|
|
|
// .where({
|
|
|
|
// .where({
|
|
|
|
// [childColumn.cn]: this.dbDriver(parentTable.tn)
|
|
|
|
// [childColumn.cn]: this.dbDriver(parentTable.tn)
|
|
|
|
// .select(parentColumn.cn)
|
|
|
|
// .select(parentColumn.cn)
|
|
|
|