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