PhilWaldmann / openrecord

Make ORMs great again!
https://openrecord.js.org
MIT License
486 stars 38 forks source link

Unable to save record without setting id when not using autoincrementing integer (serial) #38

Closed arthurfranca closed 7 years ago

arthurfranca commented 7 years ago

I have a table column id of type UUID, as primary key (not null constraint), with a default set to gen_random_uuid() from pgcrypto extension

It works if i use sql like: insert into test_table ("id") values ('84df10c9-517a-4dff-a96a-5799c30af0c4'); insert into test_table ("id") values (gen_random_uuid()); insert into test_table ("id") values (DEFAULT); insert into test_table ("another_column") values ('i am not setting uuid');

Won't work when i do:

var test = new Test({ name: 'i am not setting uuid' })
test.save(function (e) {
  console.log(e)       // false
  console.log(this.id) // null
})

Possibly a bug similar to this issue

PhilWaldmann commented 7 years ago

Hey,

you are right, that was a bug. But is has nothing to do with the linked issue.
The bug was in the postgres driver which loads the table definition. The code naively checks only for serial auto increment and adds a validatesPresenceOf validation for all attributes with a NOT NULL constraint, except for serials.

I wrote a test for that case and fixed it in version 1.10.17.

Thanks, Philipp