-
-
Notifications
You must be signed in to change notification settings - Fork 93
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
One-to-One Association keeps old records #205
Comments
Thanks for reporting this. We'll address this in the next version. |
By next version you mean rom-4.0? =) |
Nope, next bug fix release. @flash-gordon you think you could take care of this? |
@solnic sorry for being stupid here, but how is it supposed to work? Remove existing references in a before hook? |
@flash-gordon I thought about wrapping it in a transaction as a special way of handling this type of association |
yes, this should be run inside a transaction, so that possible errors won't pollute the database with partial writes, but this won't prevent from having duplicates anyway, consider this
Having a unique constraint will pause session 2 on the insert step until session 1 is completed (or rolled back). So we actually need a DB constraint. And yes, transaction is a must too :) |
@flash-gordon While I do agree that having a constraint at the database level is the right thing to do, I see no way to enforce it to the end users. Guarding against partial writes and then warning users that duplicates may end in the database, due to race conditions, if no unique constraint is in place seems more "user friendly" to me. |
Heya folks,
I was working on
hanami/model
support for one-to-one associations when I noticed that when I associate a new record the old one is kept in the database.What I expected was that issuing a create command on a one-to-one association would remove the old record (if any) and insert a new one. While it does retrieve the correct one, it leaves the database a mess and might generate constraint violation errors.
The text was updated successfully, but these errors were encountered: