backbone-relational

How do I load sub-models with a foreign key relationship in Backbone.js?

元气小坏坏 提交于 2019-12-05 17:48:07
Sorry if this is a bit convoluted... I am still learning Backbone.js... What is the proper way to load & save Backbone models that have sub-models within themselves? (And should I even be having sub-models?) For example, (pardon the coffeescript), if I have something like: class Address extends Backbone.Model urlRoot: '/api/v1/address/' url: -> return @urlRoot+@id+'/?format=json' defaults: {'city': '', 'state': ''} class Person extends Backbone.Model urlRoot: '/api/v1/person/' url: -> return @urlRoot+@id+'/?format=json' defaults: { name: 'Anon', address: new Address } ... and then I do this ..

Backbone relational events not firing?

帅比萌擦擦* 提交于 2019-12-05 09:05:10
class TheModel extends Backbone.RelationalModel relations:[ type: Backbone.HasMany key: 'subModels' relatedModel: SubModel collectionType: SubModels reverseRelation: key: 'TheModel' ] themodel = new the TheModel({subModels:[{#stuff},{#stuff},{#stuff}]}) I have createModels on so themodel.get('subModels') returns a collection of models. Now if I pass changed subModel data into mymodel themodel.set({subModels:[{changedstuff},{stuff},{stuff}]}) Shouldn't themodel throw a change event? It doesn't for me. More so if I pass identical data into mymodel themodel.set({subModels:[{samestuff},{samestuff}

Foreign key populated with an object

烂漫一生 提交于 2019-12-05 02:46:34
I would like to make a relation between two models User and Task using backbone-relational. The relation between the two models is the following: taskModel.creator_id = userModel.id // TaskModel var TaskModel = Backbone.RelationalModel.extend({ relations: [ { type: Backbone.HasOne, key: 'creator', keySource: 'creator_id', relatedModel: Users } ], // some code }); // Task collection var TaskCollection = Backbone.Collection.extend({ model: TaskModel, // some code }); // User Model var User = Backbone.RelationalModel.extend({ // some code }); Actually the problem is in the collection.models,

Backbone-relational hasmany best practices

断了今生、忘了曾经 提交于 2019-12-05 01:08:02
I am new to Backbone-relational, I am not sure what is the right way to use HasMany. I have a Parent model which have many children (by "many" I mean thousands of children). In order to avoid performance issue, I query children by their foreign key: /child/?parent=1 , instead of create a huge list of child_ids in Parent . But seems this is not the way Backbone-relational work. So I am wondering what is the right way to handle this. 1, Change my json api to include list of child id in parent, then send thousands of ids as Backbone-relational recommend: url = function(models) { return '/child/'

How to represent UML Relations with Backbone-Relational?

拈花ヽ惹草 提交于 2019-12-03 17:02:26
I have Class Diagram looking like this : ModelA 1------* ModelB 1------* ModelC 1------* ModelD Edit : The Data looks like that Data : { "Titel" : "ModelA", "ModelA" : [ { "Titel" : "ModelB1", "ModelB1" : [ { "Titel" : "ModelC1", "ModelC1":[ { "Titel" : "ModelD1" }, { "Titel" : "ModelD2" }, { "Titel" : "ModelD3" } }, { "Titel" : "ModelC2", "ModelC2":[ { "Titel" : "ModelD21" }, { "Titel" : "ModelD22" }, { "Titel" : "ModelD23" } }, ] }, { "Titel" : "ModelB2", "ModelB2" : [ { "Titel" : "ModelC1", "ModelC1":[ { "Titel" : "ModelD1" }, { "Titel" : "ModelD2" }, { "Titel" : "ModelD3" } }, { "Titel" :

Implementing a Many-to-Many relationship with Backbone-Relational

天大地大妈咪最大 提交于 2019-12-03 13:51:12
I have a simple application which defines two classes, a Person and a PersonGroup , wherein there is a many-to-many relationship in place. A Person can have no group, or be assigned to all groups, and anything in between. The example on backbonerelational.org suggests using an in-between model for many-to-many relationships, however I can't get this pattern to work with fetching (deserializing) and saving (serializing). What I want to do is use Backbone to deserialize a JSON similar to the following: { People: [ { "ID": 1, "Name": "John" }, { "ID": 2, "Name": "Bob" }, { "ID": 3, "Name": "Tim"

Creating nested models in Backbone with Backbone-relational

大兔子大兔子 提交于 2019-11-30 10:51:11
问题 I would like to use backbone-relational to have nested models in my backbone.js application. I have been able to follow the examples in the documentation to create nested objects (e.g. one-to-many relations). However I don't understand how to bind the lower level elements in a way that will update the upper level objects. I think a working application would be a very helpful tutorial. So my question is: How do I extend the Todos tutorial using backbone-relational so that: one can add/remove

How to build a Collection/Model from nested JSON with Backbone.js

て烟熏妆下的殇ゞ 提交于 2019-11-28 04:25:47
I'm relativly new to Backbone.js I have a JSON like the picture shows ! I saw some Answers in relation with Backbone-relational, but still dont get the point! How can i convert this JSON to Backbone.js Collections/Models?? I update with a code but it dont work like expected! i can't see an model when i do : My Structure is : [0] : is a collection of models [clefs] + ... + [Rest] : are collection of models (clefs) => [0] + ... + [9] : are Models(title contains a string, path too) Thanks a lot!! EDIT(10.01.12) : My Solution : window.initModel = Backbone.Model.extend({ defaults: { "title": "",

Backbone-relational submodels with RequireJS

故事扮演 提交于 2019-11-27 18:45:54
问题 I'm trying to find a way to use Backbone-relational submodels with RequireJS, where the submodels are in different files than the supermodel. For example: // app.js define(function() { var app = {}; var app.ns = {}; Backbone.Relational.store.addModelScope(app.ns); }); // Classroom/Person.js define(["app", "./Student", "./Professor"], function(app) { app.ns.Classroom.Person = Backbone.RelationalModel.extend({ subModelTypes: { 'Student': 'Classroom.Student' 'Professor': 'Classroom.Professor' },

Creating nested models with backboneJS + backbone-relational + requireJS

谁说胖子不能爱 提交于 2019-11-27 13:14:30
问题 I am new to BackboneJS and I am stuck with nested relations using Backbone-relational Model with RequireJS -I think I runned into circular issues. Any help will be highly appreciated! I have the following model and collection: /* Module Model at models/module*/ define([ 'jquery', 'underscore', 'backbone', 'backboneRelational', ], function($, _, Backbone) { var ModuleModel = Backbone.RelationalModel.extend({ urlRoot: 'api/module', _radius: 50, relations: [{ type: Backbone.HasMany, key: