javascript - Backbone - sync doesn't detect my collection url -


i have albums , songs relationship. in new album view i'm asking songs @ same time, i'm trying save album model first , save song collection , attach album.

my song collection definition:

define(function(require){    var song = require('models/songmodel');     songs = backbone.collection.extend({      url: 'songs/',               model: song,               });     return songs; }); 

i create song collection this:

this.songcollection = new songs(); //in other view saves songs files , returns hash that.songcollection.add({title:file.name,song_file:response['file_hash']}); 

then save album model , in success try save songs collection adding new album pk models in song collection:

that = this; this.model.save(null,{                                      success: function(model,response){        that.songcollection.each(function(song){                                                                                                                song.set('album',model.get('id'));        });        that.songcollection.sync('create');                                         },                    error: function(response){                                 console.log(response);                              }  }); 

however returns a 'url' property or function must specified, have specified can see previously. tried log before sync call , returns url properly. i'm missing in process? or can't create new songs in server @ once this?

you need save each song individually. sync not meant called directly, , method 'read' meant work collection. sync('read') called during collection.fetch().

that = this; this.model.save(null,{                                      success: function(model,response){        that.songcollection.each(function(song){                                                                                                                song.save({album: model.get('id')});        });                                        },                    error: function(response){                                 console.log(response);                              }  }); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -