Cannot read properties of undefined (reading 'referencedTable')
i'm just playing around with queries and i can't get this to work:without the
with
it works.
i'm passing the schemas to the db
object:and here are the two schemas:6 Replies
oh i'm dumb, i can't declare relations like this?
To use the query API, you should add the relation using
relations
in the schema file.
Check this out:
https://orm.drizzle.team/docs/rqb#declaring-relationsDrizzle Queries - DrizzleORM
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind
can i have both the references i currently have and these new relations?
You did define it in the database level, so the foreign key constraint will be enforced.
But drizzle requires some configuration to use their query selector.
Here's a quote from drizzle:
"You might've noticed that relations look similar to foreign keys — they even have a references property. So what's the difference?
While foreign keys serve a similar purpose, defining relations between tables, they work on a different level compared to relations.
Foreign keys are a database level constraint, they are checked on every insert/update/delete operation and throw an error if a constraint is violated. On the other hand, relations are a higher level abstraction, they are used to define relations between tables on the application level only. They do not affect the database schema in any way and do not create foreign keys implicitly.
What this means is relations and foreign keys can be used together, but they are not dependent on each other. You can define relations without using foreign keys (and vice versa), which allows them to be used with databases that do not support foreign keys, like PlanetScale."
You should define both in your case
gotcha, thanks
what i'm trying to get is this: and this is the code i'm using to get it:
where a
collection
is:
and liked_collections
looks like
would it be easier with queries?
or should i just stick with an array of likes inside the collection? lolIt's up to you. You have both options. Maybe you'd like to benchmark it a see what's faster?