Hi Everyone
I have added a custom field in my modal like
get fullName() {
return `${this.firstName} ${this.lastName}`;
}
I want to do the query with this custom field. Like
this.query().select(fields).where(‘fullName’, ‘ilike’, ‘%test%’)
How can i do this in objectionJS ?
You need to useraw in where or the whereRaw method.
this
.query()
.select(fields)
.whereRaw(‘("firstName" || ' ' || "lastName") ilike ?', '%test%')
You obviously cannot use the fullName getter in SQL since it's in javascript.
@koskimas I am still getting error as
column "("firstName" || ' ' || "lastName")" does not exist
You are using " around the whole thing which means an identifier in postgres. Make sure you write valid SQL. This is not specific to objection.
Most helpful comment
You need to use
rawinwhereor thewhereRawmethod.You obviously cannot use the
fullNamegetter in SQL since it's in javascript.