Skip to content

Commit

Permalink
fixed #37 - isChanged() returns true for database-loaded records
Browse files Browse the repository at this point in the history
  • Loading branch information
xavierlacot committed Jun 26, 2013
1 parent 43c30b0 commit 7d3c98e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions joli.js
Expand Up @@ -754,6 +754,7 @@ var joliCreator = function() {
table: table
};
this._data = {};
this._originalData = null;
};

joli.record.prototype = {
Expand All @@ -765,15 +766,14 @@ var joliCreator = function() {
}
},
fromArray: function(data) {
var wasNew = this.isNew ? this.isNew() : true;

if (typeof data.id !== 'undefined') {
this._originalData = {
id: data.id
};
this._originalData = this._originalData || {};
this.isNew = function() {
return false;
};
} else {
this._originalData = null;
} else if (wasNew) {
this.isNew = function() {
return true;
};
Expand All @@ -785,7 +785,7 @@ var joliCreator = function() {
this._data[colName] = null;
this._data[colName] = data[colName];

if (this._originalData && this.isNew()) {
if ((this._originalData && !this._originalData[colName]) || this.isNew()) {
this._originalData[colName] = data[colName];
}
}, this);
Expand Down

0 comments on commit 7d3c98e

Please sign in to comment.