-
My targeted query: select * from `products` where `classification` = 'stock' and `species` = 'photo' and `status` = 'approved' and `owned_by` is null and (`title` like '%color%' or `keywords` like '%color%') order by `created_at` desc; My current code: const products = await Product.query()
.where({
classification,
species,
status: 'approved',
owned_by: null,
})
.andWhere('title', 'like', `%${q}%`)
.orWhere('keywords', 'like', `%${q}%`)
.orderBy('created_at', 'desc')
.preload('prices', (builder) => builder.preload('invoices'))
.preload('seller')
.debug(true); ...which executes the following query:
Look at the parentheses around last conditions in the target query. Is it achievable w/o using raw query builder in v5? |
Beta Was this translation helpful? Give feedback.
Answered by
msrumon
Jul 25, 2020
Replies: 1 comment
-
Never knew I could write functions inside const products = await Product.query()
.where({
classification,
species,
status: 'approved',
owned_by: null,
})
// .andWhere('title', 'like', `%${q}%`)
// .orWhere('keywords', 'like', `%${q}%`)
.andWhere((builder) =>
builder
.where('title', 'like', `%${q}%`)
.orWhere('keywords', 'like', `%${q}%`)
)
.orderBy('created_at', 'desc')
.preload('prices', (builder) => builder.preload('invoices'))
.preload('seller')
.debug(true); |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
msrumon
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Never knew I could write functions inside
andWhere()
. This is the targeted code: