1602 / jugglingdb

Multi-database ORM for nodejs: redis, mongodb, mysql, sqlite3, postgresql, arango, in-memory...
http://1602.github.io/jugglingdb/
2.04k stars 241 forks source link

Create multiple relation from owner #353

Open nfleury opened 10 years ago

nfleury commented 10 years ago

If we have a relation like this :

Book = db.define('Book', {name: String});
Chapter = db.define('Chapter', {name: {type: String}});

Book.hasMany(Chapter);
Chapter.belongsTo(Book);

To add multiple chapters in a book, we have to do something like this:

book.chapters.create({name: 'a'}, function() {
    book.chapters.create({name: 'z'}, function() {
        book.chapters.create({name: 'c'}, function() {

        });
    });
});

Or something like this:

book.save(function(e,b){

Chapter.create([{name:'a',bookId:b.id},{name:'b',bookId:b.id}],function(){});

});

So, it would be nice if we could directly store multiple child objects like this:

book.chapters.create([ {name: 'a'},{name: 'v'} ], function() {}
1602 commented 10 years ago

That makes sense.