Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MySQL] Correct $returningId() implementation to correctly store selected fields #2975

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

danielsharvey
Copy link

Currently, $returningId() only works when the primary key is in the first column (of the Drizzle table definition not the underlying MySQL table).

The issues was that the local variable returning computes the selected fields in the $returningId() method but throws this away. This fix updates to correctly store config in the insert query builder.

Added test to cover this issue.

Fixes #2971

@danielsharvey danielsharvey changed the title Bugfix/fix returningid Correct $returningId() implementation to correctly store selected fields Sep 16, 2024
@danielsharvey danielsharvey changed the title Correct $returningId() implementation to correctly store selected fields [MySQL] Correct $returningId() implementation to correctly store selected fields Sep 16, 2024
Currently, $returningId() only works when the primary key is in the
first column (of the Drizzle table definition not the underlying
MySQL table).

This new test checks for this behaviour by using $returningId()
when the primary key is in the second column.

See drizzle-team#2971

Signed-off-by: Daniel Harvey <daniel@harves.net>
The local variable `returning` computes the selected fields in
$returningId() but throws this away. Change to correctly
store config in the insert query builder.

Fixed drizzle-team#2971

Signed-off-by: Daniel Harvey <daniel@harves.net>
@danielsharvey
Copy link
Author

Note that for the "limit 0" and "limit -1" tests to work, I needed this fix: 218cddb (see mysql-common.ts)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG]: MySQL $returningId does not necessarily use primary key field at runtime
1 participant