-
Notifications
You must be signed in to change notification settings - Fork 21.6k
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
Creating records with default datetimes creates but does not set the value in the new object #28229
Comments
Seems like the same issue referenced here with a Postgres default uuid. Workaround is just to reload the instance if you're willing to take the hit. |
The big negative/worry to me is that there was no indication something was amiss. I thought my default migrations were incorrect and not working for before discovering the issue. Understand it's a tough bug to fix; but wonder if there's a way to at least trigger a warning when a record is created with this type of model so the programmer is not mislead about what's going on. |
Rails knows the columns, and knows the ones with default values, it also knows the attributes going in and (by deduction) knows which attributes don't have values. Rails's RETURNING should be modified to account for this situation. |
@krainboltgreene Neither MySQL nor SQLite have an equivalent construct, so they'd have to fall back to a |
@al2o3cr Sure. |
This issue has been automatically marked as stale because it has not been commented on for at least three months. |
@rafaelfranca - any chance this could get another look? I recognize the complexity - particularly given how small a gain it would bring - but I'd suggest without it the support for database-level defaults in the current form is not feature complete. If it's not feasible, I would almost rather the framework not expose it as an option in the first place. Thanks for your consideration 🙏 |
Feel free to work on it. Right now this problem is not priority for the Rails team since there is a workaround. |
When creating records of a model with a default time migration such as
the value is created, but not present in the new object.
Steps to reproduce
Expected behavior
modified_at
should be present in the returned object.Actual behavior
modified_at
is nil.modified_at
is present in the database, and if I reload the object, it is visible.System configuration
Rails version: 5.0.1
Ruby version: 2.4.0
More info
Same result on sqlite and postgres.
The text was updated successfully, but these errors were encountered: