Closed MrGrinst closed 6 years ago
Hi @MrGrinst thanks for your feedback. By default openrecord does not write primary keys. If primary key values are present, it tries to update existing records. In you example, only one column is present (the primary key), so it wont do anything -> nothing to update!
But you could overwrite this behaviour via
// inside your model definition
this.attributes.str.primary = false
So your database will handle the primary key constraint and openrecord will handle your field as a normal string. The only downside is, that you can't query via MyTable.find('thing1')
anymore. Only via MyTable.where({str: 'thing1'})
Does this solve your problem? Or do you think the API has to be adopted for this use case.
Thanks, Philipp
@MrGrinst do you need any more help?
Nope, your recommendation should work perfectly. Thanks!
Thanks for making such a great library!
Found a small issue that affects my use case. I've got a table that has a single text column that is a primary key. The text is generated on the client and I want to save multiple rows to the table at once. However, this isn't working because it thinks the records already exist.
Table:
CREATE TABLE "my_table" ("str" varchar, PRIMARY KEY ("str"));
Attempted record creation:
store.Model('my_table').create([{ str: 'thing1' }, { str: 'thing2' }])
The problem is with the conditional at
lib/base/collection.js:242
.Works great for tables that have auto-generated/sequential primary keys, but is preventing the save from happening for these manually generated primary keys.