chore: join log
This commit is contained in:
parent
cbc806e61d
commit
9dab282bf7
|
@ -124,14 +124,13 @@ export const miRepository = {
|
|||
let appendedCondition = joinAttr.condition ? ` AND (${joinAttr.condition})` : '';
|
||||
const parentAlias = joinAttr.parentAlias;
|
||||
if (relation.isManyToOne || relation.isOneToOneOwner) {
|
||||
// JOIN `category` `category` ON `category`.`id` = `post`.`categoryId`
|
||||
const condition = relation.joinColumns.map((joinColumn) => `${destinationTableAlias}.${joinColumn.referencedColumn!.propertyPath}=${relation.propertyPath}_${joinColumn.referencedColumn!.propertyPath}`).join(' AND ');
|
||||
console.log(relation);
|
||||
const condition = relation.joinColumns.map((joinColumn) => `${destinationTableAlias}.${joinColumn.referencedColumn!.propertyPath}=${parentAlias}.${relation.propertyPath}_${joinColumn.referencedColumn!.propertyPath}`).join(' AND ');
|
||||
return ` ${joinAttr.direction} JOIN ${this.getTableName(destinationTableName)} ${this.escape(destinationTableAlias)}${
|
||||
// @ts-expect-error -- private
|
||||
this.createTableLockExpression()
|
||||
} ON ${this.replacePropertyNames(condition + appendedCondition)}`;
|
||||
} ON ${condition}${appendedCondition}`;
|
||||
} else if (relation.isOneToMany || relation.isOneToOneNotOwner) {
|
||||
// JOIN `post` `post` ON `post`.`categoryId` = `category`.`id`
|
||||
const condition = relation.inverseRelation!.joinColumns.map((joinColumn) => {
|
||||
if (relation.inverseEntityMetadata.tableType === 'entity-child' && relation.inverseEntityMetadata.discriminatorColumn) {
|
||||
appendedCondition += ` AND ${destinationTableAlias}.${relation.inverseEntityMetadata.discriminatorColumn.databaseName}='${relation.inverseEntityMetadata.discriminatorValue}'`;
|
||||
|
@ -144,9 +143,8 @@ export const miRepository = {
|
|||
return ` ${joinAttr.direction} JOIN ${this.getTableName(destinationTableName)} ${this.escape(destinationTableAlias)}${
|
||||
// @ts-expect-error -- private
|
||||
this.createTableLockExpression()
|
||||
} ON ${this.replacePropertyNames(condition + appendedCondition)}`;
|
||||
} ON ${condition}${appendedCondition}`;
|
||||
} else {
|
||||
// means many-to-many
|
||||
const junctionTableName = relation.junctionEntityMetadata!.tablePath;
|
||||
const junctionAlias = joinAttr.junctionAlias;
|
||||
let junctionCondition = '', destinationCondition = '';
|
||||
|
@ -163,7 +161,7 @@ export const miRepository = {
|
|||
} ON ${this.replacePropertyNames(junctionCondition)} ${joinAttr.direction} JOIN ${this.getTableName(destinationTableName)} ${this.escape(destinationTableAlias)}${
|
||||
// @ts-expect-error -- private
|
||||
this.createTableLockExpression()
|
||||
} ON ${this.replacePropertyNames(destinationCondition + appendedCondition)}`;
|
||||
} ON ${destinationCondition}${appendedCondition}`;
|
||||
}
|
||||
/* eslint-enable @typescript-eslint/no-non-null-assertion */
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue