chore: join log

This commit is contained in:
Acid Chicken (硫酸鶏) 2024-05-31 03:16:27 +09:00
parent cbc806e61d
commit 9dab282bf7
No known key found for this signature in database
GPG Key ID: 3E87B98A3F6BAB99
1 changed files with 5 additions and 7 deletions

View File

@ -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 */
});