cannot instantiate more than one ,,,

I have been using backbone relational (https://github.com/PaulUithol/Backbone-relational) to build my application because I have a model (Room) with lots of other models attached:

  • Room has many Comment
  • Room belongs to Location
  • As you can see in this issue I keep getting the error

    Error: Cannot instantiate more than one Backbone.RelationalModel with the same id per type

    Whenever I change View or reload a Collection.

    Now I know there is a thread here where they suggest using findOrCreate but I am not accessing models individually, but am instead using Collection.fetch . Is there a way around this problem?


    with backbone-relational you can get or create object from relational store. Use this to create relational objects:

    this.model = someModel.findOrCreate({id: 123})
    

    With this it will create new object or get existing one from relational store.

    http://backbonerelational.org/#RelationalModel-findOrCreate


    I had a similar problem, fixed it by switching to Backbone-associations.

    https://github.com/dhruvaray/backbone-associations

    The interface is almost exactly the same with only a few minor differences so porting should be pretty simple.


    I had similar problem and it happend that I need to initialize model with function:

    model: ->
    
       return new Project.Models.ModelName()
    

    When you require_tree . in application.js then model files are loaded later than collection files (alphabetical order). Setting model with function waits until the app is executed.

    链接地址: http://www.djcxy.com/p/11230.html

    上一篇: 在Windows Azure CDN中更新文件

    下一篇: 不能实例化多个,,,