canjs / can-connect

Model layer utilities for every JavaScript framework! Assemble real-time, high performance, restful data connections.
https://canjs.com/doc/can-connect.html
MIT License
29 stars 16 forks source link

can.Model 'reload' does not work #273

Closed sszabolcs closed 7 years ago

sszabolcs commented 7 years ago

How often can you reproduce it?

Description: If I give a custom id property to my can.Model and issue a findOne() command for the second time - to reload the model - can-connect/can/model/model.js does not find the id value in the response data and so it does not refresh the model in the store. model.js@1.3.8 in line 41: var idProp = inst.constructor.id || 'id'; results 'id' as idProp value but should result the custom id property name. If I rewrite this line to this: var idProp = inst.constructor.id || this.idProp || 'id'; i.e. add 'this.idProp' to the line then idProp gets the correct value, my custom id property name and the model in the store refreshes.

Steps to reproduce:

  1. Here is a fiddle which works, it uses 'stock' id property, the model is refreshed after the save, when the second findOne call finishes: https://jsfiddle.net/9uq9s7kp/

  2. Here is a fiddle with custom id prop value which does not refresh the model after the save, when the second findOne call finishes: https://jsfiddle.net/fxez1erz/

Expected results: After clicking the Save link the changeCount in the model should increase because it is increased on the 'server' side.

Environment:

Software Version
can-connect version 1.3.8
Browser Chrome 57.0.2987.133
Operating system Windows 7
justinbmeyer commented 7 years ago

I this a problem with baseMap?

imaustink commented 7 years ago

@sszabolcs I can't replicate this issue. The second JSfiddle provided seems to work correctly. I am closing this issue, for now. Feel free to re-open it if you are still having problems.

Macrofig commented 7 years ago

In reviewing the two jsfiddles, the expected behavior seems to result in each. I also couldn't seem to reproduce this locally. Perhaps I am misunderstanding the issue? cc: @sszabolcs

EDIT: Sorry, I was looking into this yesterday as well as @imaustink but Github didn't push his comment to my browser.