xavierlacot / joli.js

joli.js is an Activerecord-like javascript ORM, particularly suited for being used in the Appcelerator Titanium Mobile framework.
MIT License
267 stars 60 forks source link

isChanged meaning #37

Closed wishper closed 11 years ago

wishper commented 11 years ago

Should isChanged return true only if the record has changed? The reason of my question is the following: a simple query returns records that are 'changed' (to my great surprise): is really this the desired behaviour or did I miss something obvious?

it ('joli.record.isChanged()', function() {
    var city = models.city.findOneBy('name', 'New York')
    expect(city.isChanged()).toBeFalsy();
});
xavierlacot commented 11 years ago

isChanged() returns true if one of the properties of a record has been changed. It may be useful to check if a record has been modified and know if it needs to be persisted or not.

wishper commented 11 years ago

thank you for the reply. I'm sorry, but I'm not sure you understood my question.

on 25/06/2013 17:55, Xavier Lacot wrote:

|isChanged()| returns true if one of the properties of a record has been changed.

Changed since when? I suppose since last persist

It may be useful to check if a record has been modified and know if it needs to be persisted or not.

Luckily, It it the way I'm using it, but... IMHO, a record just read from DB needs not to be persisted again. So, again: why isChanged()==true for a record returned by a query (and not modified by anyone)?

for details, read the snipped in the op. The test does not pass. Just in case joli's logic is correct, can you please point me which is the 'change' that needs to be persisted?

thanks