1. #1
    Ext GWT Premium Member
    Join Date
    May 2010
    Location
    Ashburn, Virginia
    Posts
    48
    Vote Rating
    2
    Answers
    8
    darren102 is on a distinguished road

      1  

    Default Answered: Associated Model and Getter not being created

    Been working with an associated model and trying to get it to load per the Data Package docs but so far can only load the top level model. The raw content has the correct information in it hence i believe i must be doing something wrong in the model definitions hence any information would be appreciated.

    ProblemCauseType Model
    Code:
    Ext.define('Imms.model.ProblemCauseType', {
        extend:'Imms.model.BaseModel',
    
    
        fields:[
            { name:'Code', type:'string'},
            { name:'Name', type:'string'}
        ],
    
    
        associations:[
            { type:'hasMany', model:'ProblemCause', name:'Causes'}
        ],
    
    
        proxy: {
            type: 'rest',
            url: 'data/problemcausetypes.json',
            reader: {
                type: 'json'
            }
        }
    });
    ProblemCause Model
    Code:
    Ext.define('Imms.model.ProblemCause', {
        extend:'Imms.model.BaseModel',
    
    
        fields:[
            { name:'Code', type:'String'},
            { name:'Name', type:'string'}
        ],
    
    
        associations:[
            { type:'belongsTo', model:'ProblemCauseType', name:'CauseType'}
        ]
    });
    JSON being loaded into the Models
    Code:
    [
        {
            "__type":"DTOSerializer:#IMMSDataService.Core.DTO",
            "Id":"3e3e374c-0dba-42b9-bc8f-6ff1250a5729",
            "Name":"Internal",
            "Code":"",
            "Causes":[
                {
                    "__type":"DTOSerializer:#IMMSDataService.Core.DTO",
                    "Id":"c6914a3a-d802-4220-979c-d8d36b2dde46",
                    "Name":"Software Failure",
                    "Code":"",
                    "CauseType":{
                        "__type":"DTOSerializer:#IMMSDataService.Core.DTO",
                        "IMMSDataModelType":"ProblemCauseType",
                        "Id":"3e3e374c-0dba-42b9-bc8f-6ff1250a5729"
                    },
                    "IMMSDataModelType":"ProblemCauseDetails"
                },
                {
                    "__type":"DTOSerializer:#IMMSDataService.Core.DTO",
                    "Id":"8f7d5674-0c91-4279-994c-f40568ff6fcb",
                    "Name":"Hardware Failure",
                    "Code":"",
                    "CauseType":{
                        "__type":"DTOSerializer:#IMMSDataService.Core.DTO",
                        "IMMSDataModelType":"ProblemCauseType",
                        "Id":"3e3e374c-0dba-42b9-bc8f-6ff1250a5729"
                    },
                    "IMMSDataModelType":"ProblemCauseDetails"
                }
            ],
            "IMMSDataModelType":"ProblemCauseTypeDetails"
        },
        {
            "__type":"DTOSerializer:#IMMSDataService.Core.DTO",
            "Id":"dc59d21c-5256-4a63-aa9d-a44f53eb2dc5",
            "Name":"vl_TestProblemCauseType",
            "Code":"",
            "Causes":[
                {
                    "__type":"DTOSerializer:#IMMSDataService.Core.DTO",
                    "Id":"7c70ceff-a001-494f-9179-03f2e4769d8c",
                    "Name":"vl_TestProblemCause",
                    "Code":"56789",
                    "CauseType":{
                        "__type":"DTOSerializer:#IMMSDataService.Core.DTO",
                        "IMMSDataModelType":"ProblemCauseType",
                        "Id":"dc59d21c-5256-4a63-aa9d-a44f53eb2dc5"
                    },
                    "IMMSDataModelType":"ProblemCauseDetails"
                }
            ],
            "IMMSDataModelType":"ProblemCauseTypeDetails"
        }
    ]
    Console output looks like this:

    Code:
    Array[6]
    
    • 0: constructor
      • data: Object
        • Code: ""
        • IMMSDataModelType: "ProblemCauseTypeDetails"
        • Id: "36deae12-cef1-4285-8625-239d584bc1fb"
        • Name: "External"
        • __type: "DTOSerializer:#IMMSDataService.Core.DTO"
        • __proto__: Object
      • dirty: false
      • events: Object
      • hasListeners: HasListeners
      • id: "Imms.model.ProblemCauseType-36deae12-cef1-4285-8625-239d584bc1fb"
      • index: 0
      • internalId: "36deae12-cef1-4285-8625-239d584bc1fb"
      • modified: Object
      • phantom: false
      • raw: Object
        • Causes: Array[4]
          • 0: Object
            • CauseType: Object
            • Code: ""
            • IMMSDataModelType: "ProblemCauseDetails"
            • Id: "be0611d6-be1d-4121-a983-44c342620286"
            • Name: "Vandalism"
            • __type: "DTOSerializer:#IMMSDataService.Core.DTO"
            • __proto__: Object
          • 1: Object
          • 2: Object
          • 3: Object
          • length: 4
          • __proto__: Array[0]
        • Code: ""
        • IMMSDataModelType: "ProblemCauseTypeDetails"
        • Id: "36deae12-cef1-4285-8625-239d584bc1fb"
        • Name: "External"
        • __type: "DTOSerializer:#IMMSDataService.Core.DTO"
        • __proto__: Object
      • store: constructor
      • stores: Array[1]
      • __proto__: TemplateClass
    • 1: constructor
    • 2: constructor
    • 3: constructor
    • 4: constructor
    • 5: constructor
    Any ideas what i am doing wrong here?

  2. You should use full classname for models when defining associations.
    Code:
        Ext.define('Imms.model.ProblemCauseType', {
            extend:'Imms.model.BaseModel',
            fields:[
                { name:'Code', type:'string'},
                { name:'Name', type:'string'}
            ],
            associations:[
                { type:'hasMany', model:'Imms.model.ProblemCause', name:'Causes'}
            ],
            proxy: {
                type: 'rest',
                url: 'data/problemcausetypes.json',
                reader: {
                    type: 'json'
                }
            }
        });
    Code:
        Ext.define('Imms.model.ProblemCause', {
            extend:'Imms.model.BaseModel',
            fields:[
                { name:'Code', type:'String'},
                { name:'Name', type:'string'}
            ],
            associations:[
                { type:'belongsTo', model:'Imms.model.ProblemCauseType', name:'CauseType'}
            ]
        });

  3. #2
    Ext GWT Premium Member
    Join Date
    May 2010
    Location
    Ashburn, Virginia
    Posts
    48
    Vote Rating
    2
    Answers
    8
    darren102 is on a distinguished road

      0  

    Default Base Model

    Sorry and the base model is just a base model with our regular fields in it as shown below:

    Code:
    Ext.define('Imms.model.BaseModel', {
        extend:'Ext.data.Model',
    
    
        config: {
            idProperty:'Id'
        },
    
    
        fields:[
            { name:'Id', type:'string' },
            { name:'__type', type:'string'},
            { name:'IMMSDataModelType', type:'string'}
        ]
    });

  4. #3
    Sencha User mberrie's Avatar
    Join Date
    Feb 2011
    Location
    Bangkok, Thailand
    Posts
    506
    Vote Rating
    17
    Answers
    26
    mberrie has a spectacular aura about mberrie has a spectacular aura about

      0  

    Default

    Try adding your model class and the association type (e.g. 'Ext.data.association.HasMany') as explicit dependency via 'requires'.

    This fixed a similar problem for me - not 100% sure it is the same. Was too busy (and annoyed) to track it down and report as bug

    Might also be related to this bug report

  5. #4
    Ext GWT Premium Member
    Join Date
    May 2010
    Location
    Ashburn, Virginia
    Posts
    48
    Vote Rating
    2
    Answers
    8
    darren102 is on a distinguished road

      0  

    Default

    Thanks for replying, tried your suggestion but the same issue occurred, the ProblemCauseType is populated but the ProblemCause in the Causes association are not populated even though they are in the Raw portion of the system.

    I guess i have to keep digging for this one. Thank you for the suggestion though.

  6. #5
    Sencha User
    Join Date
    Jan 2012
    Posts
    1,376
    Vote Rating
    112
    Answers
    347
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default

    You should use full classname for models when defining associations.
    Code:
        Ext.define('Imms.model.ProblemCauseType', {
            extend:'Imms.model.BaseModel',
            fields:[
                { name:'Code', type:'string'},
                { name:'Name', type:'string'}
            ],
            associations:[
                { type:'hasMany', model:'Imms.model.ProblemCause', name:'Causes'}
            ],
            proxy: {
                type: 'rest',
                url: 'data/problemcausetypes.json',
                reader: {
                    type: 'json'
                }
            }
        });
    Code:
        Ext.define('Imms.model.ProblemCause', {
            extend:'Imms.model.BaseModel',
            fields:[
                { name:'Code', type:'String'},
                { name:'Name', type:'string'}
            ],
            associations:[
                { type:'belongsTo', model:'Imms.model.ProblemCauseType', name:'CauseType'}
            ]
        });

  7. #6
    Ext GWT Premium Member
    Join Date
    May 2010
    Location
    Ashburn, Virginia
    Posts
    48
    Vote Rating
    2
    Answers
    8
    darren102 is on a distinguished road

      0  

    Default

    Works fine with that, can i suggest updating the Data Docs to let people know, since now after a second read you are not putting the model into a package just having it as User, Post etc hence the reason it worked there. Was kind of misleading, however now i know what to look for i see the reason it was not working.

    Thank you for the answer.