hoodiehq / ember-hoodie

Build awesome offline-first Ember apps with Hoodie!
MIT License
17 stars 6 forks source link

the adapter does not serialize _id correctly, so its ignored when set in new records #66

Closed brunopedroso closed 7 years ago

brunopedroso commented 7 years ago

When I set the id field for new records, its not correctly serialized, and is therefore ignored (the db will generate it's own id instead).

When I try to save it...

    let a = this.get('store').createRecord('test', {
      id: '1',
      name: 'name 1',
    });

... ember-data raises an error:

ember.debug.js:18015 Assertion Failed: 'test:1' was saved to the server, but the response returned the new id 'B474784E-CEFE-A3CE-802D-9DF5EE30D358'. The store cannot assign a new id to a record that already has an id.
Error
    at assert (http://localhost:4200/assets/vendor.js:16561:13)
    at Object.assert (http://localhost:4200/assets/vendor.js:28312:34)
    at assert (http://localhost:4200/assets/vendor.js:102132:37)
    at Class.updateId (http://localhost:4200/assets/vendor.js:112605:41)
    at Class.didSaveRecord (http://localhost:4200/assets/vendor.js:112551:14)
    at http://localhost:4200/assets/vendor.js:113333:15
    at Backburner.run (http://localhost:4200/assets/vendor.js:11290:23)
    at Backburner.join (http://localhost:4200/assets/vendor.js:11316:23)
    at http://localhost:4200/assets/vendor.js:113323:25
    at tryCatch (http://localhost:4200/assets/vendor.js:69641:14)

and, when I query the saved record, I see this:

"{
    "name": "name 1",
    "id": "1",
    "type": "test",
    "hoodie": {
        "createdAt": "2017-05-03T18:11:22.983Z"
    },
    "_id": "B474784E-CEFE-A3CE-802D-9DF5EE30D358",
    "_rev": "1-e4a97cd486d8ccd728337c3ea41656fb"
}"

Note the id and _id fields...

gr2m commented 7 years ago

sorry for that, this is coming from https://github.com/hoodiehq/hoodie-store-client/releases/tag/v8.0.0

brunopedroso commented 7 years ago

sure... I saw that... And it looks like it was fixed (now theres a serializer in readme, with the config for _id).

But maybe this is not such a common scenario (setting the ids) and had not been tested...?

Anyway. Tks! ;-)