Model not set in Backbone Collection
Closed this issue · 1 comments
dbraynard commented
This is my first attempt to use Chaplin and I am running into an issue.
I have an existing HTML application that uses Backbone. It makes a call to a rest api to synchronize a collection. I'm attempting to port this code to use Chaplin.
The problem is that after a rest api call finishes, the Backbone.Collection object does not have its model assigned so the Collection.Set method fails. I discovered this stepping through the javascript executing in Chrome.
My chaplin model is defined below:
define [
'underscore'
'chaplin'
'models/base/collection'
'models/apple'
], (_, Chaplin, Collection, Apple) ->
'use strict'
class Apples extends Collection
# Mix in a SyncMachine
_.extend @prototype, Chaplin.SyncMachine
comparator: 'id'
# rest api address
url: "//localhost:3000/api/fruits"
model: Apple
initialize: ->
super
# parse method
parse: (data) ->
console.log 'in parse method'
response = data.response
#does some parsing here....
The precise line where things error out in backbone.js is line 683
id = attrs[targetModel.prototype.idAttribute];
this.model is undefined
dbraynard commented
It was my fault, I didn't actually put any code inside the Apple model implementation.