值为空不返回第一条

This commit is contained in:
COOL 2025-01-18 18:22:11 +08:00
parent f0ab1a14e3
commit 4ccb08cb49
2 changed files with 15 additions and 6 deletions

View File

@ -2462,8 +2462,8 @@ export class SelectQueryBuilder extends QueryBuilder {
else { else {
let andConditions = []; let andConditions = [];
for (let key in where) { for (let key in where) {
if (where[key] === undefined || where[key] === null) // if (where[key] === undefined || where[key] === null)
continue; // continue;
const propertyPath = embedPrefix ? embedPrefix + "." + key : key; const propertyPath = embedPrefix ? embedPrefix + "." + key : key;
const column = metadata.findColumnWithPropertyPathStrict(propertyPath); const column = metadata.findColumnWithPropertyPathStrict(propertyPath);
const embed = metadata.findEmbeddedWithPropertyPath(propertyPath); const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
@ -2518,7 +2518,11 @@ export class SelectQueryBuilder extends QueryBuilder {
// const parameter = this.connection.driver.createParameter(parameterName, parameterIndex - 1); // const parameter = this.connection.driver.createParameter(parameterName, parameterIndex - 1);
// andConditions.push(`${aliasPath} = ${parameter}`); // andConditions.push(`${aliasPath} = ${parameter}`);
// } // }
andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, parameterValue))); if (parameterValue === undefined || parameterValue === null) {
andConditions.push(`${aliasPath} IS NULL`);
}else{
andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, parameterValue)));
}
// this.conditions.push(`${alias}.${propertyPath} = :${paramName}`); // this.conditions.push(`${alias}.${propertyPath} = :${paramName}`);
// this.expressionMap.parameters[paramName] = where[key]; // todo: handle functions and other edge cases // this.expressionMap.parameters[paramName] = where[key]; // todo: handle functions and other edge cases
} }

View File

@ -2465,8 +2465,8 @@ class SelectQueryBuilder extends QueryBuilder_1.QueryBuilder {
else { else {
let andConditions = []; let andConditions = [];
for (let key in where) { for (let key in where) {
if (where[key] === undefined || where[key] === null) // if (where[key] === undefined || where[key] === null)
continue; // continue;
const propertyPath = embedPrefix ? embedPrefix + "." + key : key; const propertyPath = embedPrefix ? embedPrefix + "." + key : key;
const column = metadata.findColumnWithPropertyPathStrict(propertyPath); const column = metadata.findColumnWithPropertyPathStrict(propertyPath);
const embed = metadata.findEmbeddedWithPropertyPath(propertyPath); const embed = metadata.findEmbeddedWithPropertyPath(propertyPath);
@ -2490,6 +2490,11 @@ class SelectQueryBuilder extends QueryBuilder_1.QueryBuilder {
: (parameterValue = : (parameterValue =
ApplyValueTransformers_1.ApplyValueTransformers.transformTo(column.transformer, parameterValue)); ApplyValueTransformers_1.ApplyValueTransformers.transformTo(column.transformer, parameterValue));
} }
if (parameterValue === undefined || parameterValue === null) {
andConditions.push(`${aliasPath} IS NULL`);
}else{
andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, parameterValue)));
}
// if (parameterValue === null) { // if (parameterValue === null) {
// andConditions.push(`${aliasPath} IS NULL`); // andConditions.push(`${aliasPath} IS NULL`);
// //
@ -2521,7 +2526,7 @@ class SelectQueryBuilder extends QueryBuilder_1.QueryBuilder {
// const parameter = this.connection.driver.createParameter(parameterName, parameterIndex - 1); // const parameter = this.connection.driver.createParameter(parameterName, parameterIndex - 1);
// andConditions.push(`${aliasPath} = ${parameter}`); // andConditions.push(`${aliasPath} = ${parameter}`);
// } // }
andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, parameterValue))); // andConditions.push(this.createWhereConditionExpression(this.getWherePredicateCondition(aliasPath, parameterValue)));
// this.conditions.push(`${alias}.${propertyPath} = :${paramName}`); // this.conditions.push(`${alias}.${propertyPath} = :${paramName}`);
// this.expressionMap.parameters[paramName] = where[key]; // todo: handle functions and other edge cases // this.expressionMap.parameters[paramName] = where[key]; // todo: handle functions and other edge cases
} }