drizzle-team / drizzle-team/drizzle-orm
[BUG]: $returningId returns an empty array unless primaryKey() is put directly on the column
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
### Report hasn't been filed before.
- [x] I have verified that the bug I'm about to report hasn't been filed before.
### What version of `drizzle-orm` are you using?
0.40.1
### What version of `drizzle-kit` are you using?
0.30.5
### Other packages
_No response_
### Describe the Bug
DB: mysql
orm: 0.40.1
kit: 0.30.5
$returningId() should return the inserted row's ID, but it returns an empty array unless primaryKey() is added to the column directly, instead of in the callback.
The following works fine.
```
export const table = mysqlTable("table", {
id: serial().notNull().primaryKey()
},
(table) => [
primaryKey({ columns: [table.id], name: "id"}),
]);
```
This does not work
```
export const table = mysqlTable("table", {
id: serial().notNull()
},
(table) => [
primaryKey({ columns: [table.id], name: "id"}),
]);
```
Not a huge problem, just add primaryKey to the column right? Well, not if you constantly pull the schema from the DB. The generated schema will not add primaryKey to the column directly, only in the callback function, so you have to manually add it to all columns every time you pull the schema.
Contributor guide
Assessment
This issue has not been assessed yet.