coresmart / persistencejs

persistence.js is an asynchronous Javascript database mapper library. You can use it in the browser, as well on the server (and you can share data models between them).
http://persistencejs.org
1.73k stars 240 forks source link

Why persistence.flush is executed when .selectJSON called? #159

Closed AleksMeshkov closed 9 years ago

AleksMeshkov commented 9 years ago

Hello!

If I create a new obejct

var c = new Category({name: "Main category"});
persistence.add(c);

then run

Category.all().selectJSON(...)

that object will be saved into the database even without running persistence.flush(). Should it be so? Can I somehow prevent this?

AleksMeshkov commented 9 years ago

By the way, can I somehow rollback entity's changed (dirty) attributes to the last saved (flushed) state?

upd: I think I'v found it. It's persistence.clean(), right?

zefhemel commented 9 years ago

Every query you execute (e.g. list) will automatically flush, so that the query results will reflect changes made "locally" (i.e. not in the database). Indeed, clean() should reset "local" changes.

AleksMeshkov commented 9 years ago

Thank you, @zefhemel!