Skip to content
This repository has been archived by the owner on Aug 5, 2021. It is now read-only.

Commit

Permalink
update bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Philipp Waldmann committed Feb 18, 2014
1 parent 3db36e0 commit 92979b1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 10 deletions.
7 changes: 0 additions & 7 deletions lib/stores/sql/save.js
Expand Up @@ -75,13 +75,6 @@ exports.record = {
condition[primary_keys[i]] = this[primary_keys[i]];
}

if(!this.hasChanges()){
if(options.commit !== false){
options.transaction.commit();
}
return callback(true);
}


this.callInterceptors('beforeUpdate', [options.transaction], function(okay){
if(okay){
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "openrecord",
"version": "0.3.0",
"version": "0.3.1",
"description": "Active record like ORM for nodejs",
"keywords": ["orm", "record", "sql", "sqlite3", "postgres", "pg", "mysql", "database", "activerecord"],
"author": "Philipp Waldmann <philipp.waldmann@s-team.at>",
Expand Down
24 changes: 24 additions & 0 deletions test/sql/__shared/updates-test.js
Expand Up @@ -212,6 +212,30 @@ module.exports = function(title, beforeFn, afterFn, store_conf){
});
});
});


it('create only nested record', function(next){
store.ready(function(){
var User = store.Model('User');
var Post = store.Model('Post');
User.find(3).include('posts').exec(function(admin){
admin.posts.length.should.be.equal(0);

admin.posts.add({thread_id:4, message: 'admin was here'});

admin.save(function(result){
result.should.be.equal(true);

Post.where({user_id:3}).count().exec(function(result){
result.count.should.be.equal(1);
next();
});

});

});
});
});



Expand Down
2 changes: 1 addition & 1 deletion test/sql/postgres/run_shared-tests.js
Expand Up @@ -60,7 +60,7 @@ testPG('updates', [
'CREATE TABLE users(id serial primary key, login TEXT, email TEXT, created_at TEXT)',
'CREATE TABLE posts(id serial primary key, user_id INTEGER, thread_id INTEGER, message TEXT)',
'CREATE TABLE threads(id serial primary key, user_id INTEGER, title TEXT)',
"INSERT INTO users(login, email, created_at) VALUES('phil', 'phil@mail.com', '2014-01-05'), ('michl', 'michl@mail.com', '2014-01-10'), ('admin', 'admin@mail.com', '2014-01-01')",
"INSERT INTO users(login, email, created_at) VALUES('phil', 'phil@mail.com', '2014-01-05'), ('michl', 'michl@mail.com', '2014-01-10'), ('admin', 'admin@mail.com', '2014-01-01'), ('administrator', 'administrator@mail.com', '2014-01-01')",
"INSERT INTO posts(user_id, thread_id, message) VALUES(1, 1, 'first message'), (1, 1, 'second'), (1, 2, 'third'), (2, 1, 'michls post')",
"INSERT INTO threads(user_id, title) VALUES(2, 'first thread'), (1, 'second thread')"
]);
Expand Down
2 changes: 1 addition & 1 deletion test/sql/sqlite3/runs_shared-tests.js
Expand Up @@ -59,7 +59,7 @@ testSQLite('updates', [
'CREATE TABLE users(id INTEGER PRIMARY KEY AUTOINCREMENT, login TEXT, email TEXT, created_at TEXT)',
'CREATE TABLE posts(id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER, thread_id INTEGER, message TEXT)',
'CREATE TABLE threads(id INTEGER PRIMARY KEY AUTOINCREMENT, user_id INTEGER, title TEXT)',
'INSERT INTO users(login, email, created_at) VALUES("phil", "phil@mail.com", "2014-01-05"), ("michl", "michl@mail.com", "2014-01-10"), ("admin", "admin@mail.com", "2014-01-01")',
'INSERT INTO users(login, email, created_at) VALUES("phil", "phil@mail.com", "2014-01-05"), ("michl", "michl@mail.com", "2014-01-10"), ("admin", "admin@mail.com", "2014-01-01"), ("administrator", "administrator@mail.com", "2014-01-01")',
'INSERT INTO posts(user_id, thread_id, message) VALUES(1, 1, "first message"), (1, 1, "second"), (1, 2, "third"), (2, 1, "michls post")',
'INSERT INTO threads(user_id, title) VALUES(2, "first thread"), (1, "second thread")'
]);
Expand Down

0 comments on commit 92979b1

Please sign in to comment.