DT
Drizzle Teampaaradiso
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:P
paaradiso•178d ago
oh i'm dumb, i can't declare relations like this?
A
Ahmed•178d ago
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
P
paaradiso•178d ago
can i have both the references i currently have and these new relations?
A
Ahmed•178d ago
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
P
paaradiso•178d ago
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? lolA
Angelelz•178d ago
It's up to you. You have both options. Maybe you'd like to benchmark it a see what's faster?
The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!
7.2KMembers
View on DiscordWant results from more Discord servers?
More PostsKey columns "user_id" and "id" are of incompatible types: text and bigint.I'm getting the error in the title ^ but they're the same type.
```js
export const usersTable = pgTMigration Failed LibsqlErrorI had migrated prior, done a lot of schema work, and then did a drizzle-generate, worked fine and I[Solved] cannot find package 'mysql2'I've setup drizzle with a planetscale db and pushed a simple user schema, however running the pnpm dError: this.client.prepare is not a functionI am trying to build a project using Bun, Hono and Drizzle.
When i am starting the project with thispg: introspect failsSo I have some tables that do not have a primary key constraint (by design) and it seems that drizzlclient connection refusedI'm using bun.
I was able to get the pool connection working, but the same connection configuratioRunning migrations in server-less (edge) land??According to the docs:
```
// this will automatically run needed migrations on the database
await mIs there any way to call drizzle-kit with the new node --env-file=.env argument?Hey, since node supports env files since pretty recently, it would be nice if we could ditch dotenv.enumerating tablesI have a table of possible 'statuses' for a column in my records table and would like my zod schema how to group Related Items```typescript
// index.ts
const coursesList = await db
.select({ title: courses.title, tags: tagsNested where filter, how to not include emptyThe following almost works
```
const query = db.query.productionItem.findMany({
with: {
itemStis placeholder in prepare statements deprecated!??```typescript
const courses = db.query.userCourses
.findMany({
where: eq(placeholder("userId")SQLite json_eachHi. I wandted to use the json_each function in sqlite, but I dont think the query is building correcForeign key truncated for being too long?Hi,
I have multiple warnings / notices:
`{
severity_local: 'NOTICE',
severity: 'NOTICE',
codedrizzle-zod with custom typesI have defined opaque types in my application and have implemented those in the drizzle schema (awesUsing transactions in automated testing like JestI have a testing set-up as follows:
1. Start postgres container
2. Apply migrations to db
3. Jest tTypeScript complaining about using a spread operator in partial select queryTypeScript complaining about me using a spread operator in partial select query.
I have the followiUnable to read error message when inserting withdb.insert().values()Hey there, i am using visual studio code and am developing with nuxt3. I am trying to insert an objehow to add new driver to drizzle?what is the procedure of adding a new driver to drizzle orm?`drizzle-kit --custom` is not giving me a blank migration fileI'm doing the following:
```sh
drizzle-kit generate:pg --custom
```
But it's not giving me a blank