简体   繁体   中英

backbone relational not updating

I have a relationship setup between my user object and my usergame object. The relationship appears to be setup correctly, i can access usergames through a user object.

However, when I create a new usergame object, the user object does not update.

Could someone offer me a solution to this?

Relationship is setup like so:

class App.Models.User extends Backbone.RelationalModel
  urlRoot: '/user'

  relations: [
    type: Backbone.HasMany
    key: 'user_games'
    relatedModel: 'App.Models.UserGame'
    includeInJSON: true
    collectionType: 'App.Collections.UserGames'
    reverseRelation:
      key: 'user'
  ]

From the documentation :

Q : (Reverse) relations or submodels don't seem to be initialized properly (and I'm using CoffeeScript!)

A : You're probably using the syntax class MyModel extends Backbone.RelationalModel instead of MyModel = Backbone.RelationalModel.extend . This has advantages in CoffeeScript, but it also means that Backbone.Model.extend will not get called. Instead, CoffeeScript generates piece of code that would normally achieve roughly the same. However, extend is also the method that Backbone-relational overrides to set up relations and other things as you're defining your Backbone.RelationalModel subclass.

That's a shame, as I like Coffeescript's extend syntax. Try it without, as explained in the documentation?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM