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" : "ModelC2",
"ModelC2":[
{ "Titel" : "ModelD21" },
{ "Titel" : "ModelD22" },
{ "Titel" : "ModelD23" }
},
]
}]
}
I create those RelationalModel :
ModelA :
ModelA = Backbone.RelationalModel.extend({
relations:[{
type: Backbone.HasMany,
key: 'modelb',
relatedModel: 'ModelB',
collectionType: 'ModelBCollection',
reverseRelation:{
key: 'belong To',
includeInJSON: 'id'
}
}] });
ModelB :
ModelB = Backbone.RelationalModel.extend({
relations:[{
type: Backbone.HasMany,
key: 'modelc',
relatedModel: 'ModelC',
collectionType: 'ModelCCollection',
reverseRelation:{
key: 'belong To',
includeInJSON: 'id'
}
}] });
ModelC :
ModelC = Backbone.RelationalModel.extend({
relations:[{
type: Backbone.HasMany,
key: 'modeld',
relatedModel: 'ModelD',
collectionType: 'ModelDCollection',
reverseRelation:{
key: 'belong To',
includeInJSON: 'id'
}
}] });
ModelD :
ModelD = Backbone.Model.extend({ });
Collections :
ModelACollection = Backbone.Collection.extend({ model: ModelA });
ModelBCollection = Backbone.Collection.extend({ model: ModelB });
ModelCCollection = Backbone.Collection.extend({ model: ModelC });
ModelDCollection = Backbone.Collection.extend({ model: ModelD });
and i do this in the Router :
Router :
var obja = new ModelACollection(data);
var objb = new ModelBCollection(data.objb);
var objc = new ModelCCollection(data.objc);
var objd = new ModelDCollection(data.objd);
all get fetched but with many warning (firefox, chrome) looks like this :
Warning :
Relation=%o; no model, key or relatedModel (%o, %o, %o) ....
- What is the meaning of this Warning?
- That's the right to represent this Class Relation with Backbone-relational isn't?
if not?
How can i represent this as a Backbone ModelRelational?
In Model A you are defining
key: 'modelb'
which links to Model B. However, key should be "a string. References an attribute name on relatedModel" (based on the docs). And I cannot see and model field called modelb
来源:https://stackoverflow.com/questions/9225640/how-to-represent-uml-relations-with-backbone-relational