Keep dirty state for cached objects
This commit is contained in:
parent
12ea5f8478
commit
8b720c30f8
|
@ -181,6 +181,12 @@ AbstractClass.all = function all(params, cb) {
|
||||||
// TODO: think about better implementation, test keeping dirty state
|
// TODO: think about better implementation, test keeping dirty state
|
||||||
if (constr.cache[d.id]) {
|
if (constr.cache[d.id]) {
|
||||||
obj = constr.cache[d.id];
|
obj = constr.cache[d.id];
|
||||||
|
// keep dirty attributes untouthed (remove from dataset)
|
||||||
|
Object.keys(obj.toObject()).forEach(function (attr) {
|
||||||
|
if (attr in d && obj.propertyChanged(attr)) {
|
||||||
|
delete d[attr];
|
||||||
|
}
|
||||||
|
});
|
||||||
constr.call(obj, d);
|
constr.call(obj, d);
|
||||||
} else {
|
} else {
|
||||||
obj = new constr(d);
|
obj = new constr(d);
|
||||||
|
|
|
@ -272,5 +272,14 @@ it 'should validate uniqueness', (test) ->
|
||||||
user.email = 'unique@email.tld'
|
user.email = 'unique@email.tld'
|
||||||
user.isValid (valid) ->
|
user.isValid (valid) ->
|
||||||
test.ok valid, 'valid with unique email'
|
test.ok valid, 'valid with unique email'
|
||||||
test.done()
|
user.save ->
|
||||||
|
test.done()
|
||||||
|
|
||||||
|
it 'should save dirty state when validating uniqueness', (test) ->
|
||||||
|
User.all where: email: 'unique@email.tld' , (err, users) ->
|
||||||
|
u = users[0]
|
||||||
|
u.name = 'Hulk'
|
||||||
|
u.isValid (valid) ->
|
||||||
|
test.ok valid
|
||||||
|
test.equal u.name, 'Hulk'
|
||||||
|
test.done()
|
||||||
|
|
Loading…
Reference in New Issue