0
votes

Backbone only fills in first model from collection when I fetch.

@leadgen_forms = new app.collections.LeadgenForms [],
    { event_provider_id: @event_provider_id }
@leadgen_forms.fetch
  success: _.bind ((collection, response) ->
    debugger

When I inspect collection from success:

enter image description here

The image above shows a length of 11 but only a single model. I know that if each model doesn't have a unique id, then backbone treats the models as duplicates. However, when i inspect the data returned from the JSON service, all all ids are unique and everything else looks kosher:

enter image description here

From the model:

window.app.models.LeadgenForm = Backbone.Model.extend
  initialize: (model, options) ->
    @event_provider_id = options.event_provider_id
    @id = options.id

  url: ->
    if @id
      '/event_providers/' + @event_provider_id + '/leadgen_forms/' + @id
    else
      '/event_providers/' + @event_provider_id + '/leadgen_forms'

window.app.collections.LeadgenForms = Backbone.Collection.extend
  model: window.app.models.LeadgenForm

  initialize: (collection, options) ->
    @event_provider_id = options.event_provider_id

  parse: (response) ->
    debugger
    return response

  url: ->
    '/event_providers/' + @event_provider_id + '/leadgen_forms'
1
Can you please include any parse method you may have on the collection or its associated model? Also, what is the model's idAttribute?Platinum Azure

1 Answers

0
votes

It appears my problem was this line from the model:

@id = options.id

When a new model was instantiated the ID would be set to null (except for the first model).