`Error: no such column: unboxes.rarity` with `findMany()`
Hello. I am getting the error
Error: no such column: unboxes.rarity
despite not using unboxes.rarity
The error comes fron the where
in the query below. Is this a bug?
Code:
My items
schema:
21 Replies
You're using
query
- did you defined and exported relations for your tables?Yes, like this:
And the "main" table schema
This works:
This doesn't work:
Surely you should be able to do this with the query API
?
This is the SQL .findMany() generates
```sql
select "id", "case_id", "item_id", "is_stat_trak", "unboxer_id", "unboxed_at", (select json_array("id", "name", "description", "image", "rarity", "phase") as "data" from (select * from "items" "unboxes_item" where "unboxes_item"."id" = "unboxes"."item_id" limit ?) "unboxes_item") as "item", (select json_array("id", "type", "name", "description", "image") as "data" from (select * from "cases" "unboxes_case" where "unboxes_case"."id" = "unboxes"."case_id" limit ?) "unboxes_case") as "case" from "unboxes" where "unboxes"."rarity" in (?, ?)
```
No clue why it does
where "unboxes"."rarity" in (?, ?)`Apologies for the ping @Angelelz, but I saw you in an issue that might be relevant
RE: https://github.com/drizzle-team/drizzle-orm/issues/1069
Is my issue related to this do you think?
GitHub
[FEATURE]: Add back filtering by nested relations in relational que...
Describe what you want Filtering by nested relations is a common thing to do and was recently removed to improve performance. I propose a syntax to add this feature back into the relational queries...
Yes, you are hitting that issue
You can make it work by using a subquery in the where
Can you put your code in drizzle.run and send me the link, I might be able to help you later
Thanks, I'll try that
Got it here: https://drizzle.run/tt5dzixcs01b0bkfwzj0e6mj
Drizzle Run
Mozzy's issue - Drizzle Run
I managed to solve it I think
Full function
It does feel like a very janky workaround though. What were the performance issues that lead this to being removed?
This is the workaround I use for this type of scenario: https://drizzle.run/eaos0upq5ce52yuvezbqhg1s
Drizzle Run
undefined - Drizzle Run
You can't have items.rarity in the
where
of a unboxes table directly.
It's basically what you didI can't access that link
It's exactly what you did, I had not seen your response by the time I changed it
Okay thanks
drizzle.run is a really cool tool
It was written by one of the advocates
One of the reasons is that you could hit performance penalties unless you know what you're doing
The relational query API doesn't require foreign keys or indexes to work, but if you don't use them, it will probably be very bad
The relational query API being findFirst() and findMany()?
Yes
Is the performance of the workaround similar to the removed feature?
or, could-be-performance
I'm not sure, I didn't understand how it worked when it existed
But the work around will be fine if you have foreign keys and correct indexes
Good, I think I do