custom join by condition
This commit is contained in:
parent
6d5d8d9ded
commit
fd2f49f175
1 changed files with 11 additions and 4 deletions
|
@ -117,7 +117,16 @@ export default abstract class DynamicQueryBuilder {
|
|||
if (queryObject.join) {
|
||||
for (const join of queryObject.join) {
|
||||
let subaffix = join.id ?? StringHelper.random(10);
|
||||
query.leftJoin(`${alias}.${join.foreignColumn}`, `${subaffix}_${join.table}`);
|
||||
if (join.type == undefined) join.type = "defined";
|
||||
if (join.type == "defined") {
|
||||
query.innerJoin(`${alias}.${join.foreignColumn}`, `${subaffix}_${join.table}`);
|
||||
} else {
|
||||
let condition = join.condition
|
||||
.replaceAll(`${join.table}.`, `${subaffix}_${join.table}.`)
|
||||
.replaceAll(`${queryObject.table}.`, `${alias}.`);
|
||||
|
||||
query.innerJoin(join.table, `${subaffix}_${join.table}`, condition);
|
||||
}
|
||||
|
||||
this.buildDynamicQuery(query, join, subaffix, depth + 1);
|
||||
}
|
||||
|
@ -129,7 +138,6 @@ export default abstract class DynamicQueryBuilder {
|
|||
conditions: Array<ConditionStructure>,
|
||||
alias: string
|
||||
): void {
|
||||
console.log(conditions, alias);
|
||||
for (const condition of conditions) {
|
||||
if (condition.structureType == "condition") {
|
||||
const whereClause = this.buildConditionClause(condition, alias);
|
||||
|
@ -239,8 +247,6 @@ export default abstract class DynamicQueryBuilder {
|
|||
parameters[`${parameterKey}_end`] = new Date(new Date().getFullYear() - (condition.value as number), 11, 31);
|
||||
}
|
||||
|
||||
console.log(query, parameters);
|
||||
|
||||
return { query, parameters };
|
||||
}
|
||||
|
||||
|
@ -417,6 +423,7 @@ const memberByRunningMembershipQuery: DynamicQueryStructure = {
|
|||
table: "membership",
|
||||
where: [{ structureType: "condition", concat: "_", operation: "null", column: "end", value: "" }],
|
||||
foreignColumn: "memberships",
|
||||
type: "defined",
|
||||
},
|
||||
],
|
||||
orderBy: [
|
||||
|
|
Loading…
Add table
Reference in a new issue