How to represent UML Relations with Backbone-Relational?
Asked Answered
P

1

4

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) .... 
  1. What is the meaning of this Warning?
  2. 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?

Pectinate answered 10/2, 2012 at 9:37 Comment(1)
Hi Mr Smith! i edited my Post and add some Data! Thank you!Pectinate
B
0

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

Burundi answered 13/8, 2012 at 17:24 Comment(3)
Is that a question or and answer?Pectinate
If you have provided your full model code in the question, then this is the answer: you do need a a field with name "modelb" if you want the refer to it with key. If modelb does not exist, how should the look up work? Maybe key should simply be 'id'.Burundi
can you edit your post with a visual response(example)? Thank you!Pectinate

© 2022 - 2024 — McMap. All rights reserved.