-
-
Notifications
You must be signed in to change notification settings - Fork 544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
QueryBuilder using having with calculated column #734
Comments
I think this should actually work, but you need to define the @Property({ persist: false })
distance?: number; Otherwise it would not be even mapped to your entity when doing |
Sorry, I forgot to add the entity to the issue: @Entity({ tableName: "studio" })
export default class StudioEntity {
@PrimaryKey()
public id!: number;
@Property({ columnType: "point srid 4326" })
public position!: unknown;
@Property({ persist: false })
public distance?: number;
} As you can see, I already have define the |
If mikro-orm/packages/knex/src/query/QueryBuilder.ts Lines 159 to 166 in 0474787
by this: having(cond: QBFilterQuery | string, params?: any[]): this {
cond = QueryHelper.processWhere(cond as Dictionary, this.entityName, this.metadata);
if (Utils.isString(cond)) {
cond = { [`(${cond})`]: Utils.asArray(params) };
}
this._having = CriteriaNode.create(this.metadata, this.entityName, cond).process(this);
return this;
} |
Interesting, it is actually caused by the complex query condition, it works fine with just |
worked like charm!! I added a new column used by the orderBy, in my entity and now works, THANK YOU! |
Is your feature request related to a problem? Please describe.
The clausule
having
accept the use of calculated columns andQueryBuilder.having
permit useQBFilterQuery
sintaxis:But using this sintaxis don't permit use calculated columns:
Describe the solution you'd like
If the column is marked as
persist: false
in the entity use the column as is, in this case,distance
and note0.distance
. Or maybe require a prefix, for example "$", to indicate that is a calculated column, in this case,query.having({ $distance: { $gte: cursor.distance })
.Describe alternatives you've considered
Use the string sintaxis:
Additional context
I like the QBFilterQuery syntax better and it is the one I use in other queries so I would like to maintain consistency.
The text was updated successfully, but these errors were encountered: