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

[BUG] PK not set properly when creating a record w/ a hasOne relationship #739

Open
nickschot opened this issue Jan 10, 2019 · 1 comment

Comments

@nickschot
Copy link
Contributor

  • Platform: macOS 10.14
  • Database: postgres 9.6
  • Lux Version: 1.2.3
  • Node Version: 11

Having two models with a hasOne <-> belongsTo relationship, when creating the model which has the hasOne side two queries are run:

  1. The main INSERT query (which has a returning 'id' statement)
  2. An UPDATE query which sets the relationship on the record with the belongsTo side (Created by: https://github.com/postlight/lux/blob/master/src/packages/database/model/index.js#L1229 )

Due to the way the queries are built (and run), the PK is not correctly set on the UPDATE query resulting in a 'nextval(''transactions_id_seq''::regclass)' in Postgres. The newly created PK is only set on the model after the transaction with the queries has completed. See: https://github.com/postlight/lux/blob/master/src/packages/database/model/index.js#L1243 through line 1246.

@zacharygolba it would be great if you could comment on this. I have been debugging lux for a while now, but haven't fully got an idea of how to fix this without fully overhauling the query builder/runner.

PS. #737 is caused by this too.

@nickschot
Copy link
Contributor Author

Fix is in #737

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

No branches or pull requests

1 participant