2016-03-18 7 views
0

ich eine Eins-zu viele Beziehung zu retten versuche Meine ModelleBookshelf.js speichern one to many Beziehung

Foo

foo = bookshelf.Model.extend({ 
     tableName: 'foo', 
     bar: function() { 
      return this.hasMany('bar', 'barId'); 
     } 

Bar

bar = bookshelf.Model.extend({ 
     tableName: 'bar', 
     foo: function() { 
      return this.belongsTo('foo', 'barId'); 
     } 

sind Was Ich versuche zu tun

var Foo = { id: 7 } 
new Bar({ blah: blah.val }) 
       .foo() 
       .attach(foo); 

Der Fehler Ich erhalte

(intermediate value).foo().attach is not a function

Jede Hilfe wird geschätzt.

Antwort

0

Ich glaube nicht, dass Sie Daten so speichern können. Ich gehe davon aus, dass die Tabelle barfoo_id Säule hat, so alles, was Sie tun müssen, ist

new Bar().save({ blah: blah.val, foo_id: Foo.id}).then(function(){});