-
Notifications
You must be signed in to change notification settings - Fork 73
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
zero values inserted for nil pointers #146
Comments
Hi George, sorry for a long delay – that message was buried in my inbox. What you hit is actually one of the hardest issues in reform design, and in ORMs in general – mapping of database default values to code. The second proprietary version of reform used reform/internal/test/models/good.go Lines 25 to 65 in 161dee9
|
See also #100. |
Hi AlekSi, thanks for the reply, and no worries on the delay. Perhaps I assumed too much, but from the example in the README:
... I assumed that pointer fields (Email, UpdatedAt in this example) were a way to express "no value given", and that reform would ignore such nils, rather than inserting zero values. If that is not the case (design decision due to common bugs, as you mentioned), what is the purpose of having one I ended up using a constructor for my models that fills in the CreatedAt field for me (similar to your |
That means that one normally should use pointers for |
I have a model with a nil-able time field, and rather than letting the database fill it in, reform is causing inserts to have zero-based dates.
My model is like:
And my table (this is postgres):
If I use reformdb and the postgres driver, it inserts the zero value for time, rather than letting the DB fill it in. It generates SQL like the following:
I think the presence of the column "created_at" in the generated SQL is causing the zero-value insert.
If I insert into this table manually without a "created_at" field, the DB automatically fills it in for me using CURRENT_TIMESTAMP.
Am I doing something wrong here? I'm using reform via dep, locked to git revision
161dee9
Thanks very much.
The text was updated successfully, but these errors were encountered: