Hello, I'm expecting a query to return results wit...
# orm-help
f
Hello, I'm expecting a query to return results with a
where
OR
condition but I get nothing back, this is what it looks like:
Copy code
await prisma.transaction.findMany({
		where: {
			OR: [
				{
					description: {
						contains: paramKeyword ? paramKeyword : undefined
					},
					value: {
						equals:
							paramKeyword && !isNaN(parseInt(paramKeyword)) ? parseInt(paramKeyword) : undefined
					}
				}
			]
		}
	});
Basically I'm trying to implement a really basic search from url params. The column types are
description: string
and
value: number
. If I comment
description
or
value
and change nothing else I do get results, but when both conditions are present I get an empty array. Not sure if it matters, but this is on a SQLite db. What am I missing? Thanks!
1
m
@Fernando It seems to me like your OR array only has one element: an object with properties description & value. I think what you probably want is to remove the outer braces (the ones directly inside the square brackets.
Copy code
OR: [
  {description: {...}},
  {value: {...}}
]
That's interesting that you get results when you comment out description or value. I think what you're actually seeing there is that you're essentially performing this logic: OR ((A AND B)) - which is equivalent to (A AND B) In other words, your query seems exactly equivalent to if you dropped the OR altogether. You're not ORing at the right level. It's:
OR: [{query obj 1}, {query obj 2}, ...]
You've got:
OR: [{{query obj 1}, {query obj 2}}]
, where since your two query statements are in one object, it's an implicit AND.
f
Oh, understood! Thanks for the clarification, works as expected now 👍
m
You're welcome. 🙂