Extjs 5.0 nested association in model throws error = Ext.data.schema.Schema.addEntity (): Duplicate object name
I am having problems setting nested link associations that are reused across different models.
How can I do that?
AddressModel
Ext.define('POC.model.AddressModel',
{
extend: 'Ext.data.Model',
fields: [
{ name:'id', type:'string' },
{ name:'line1', type:'string' },
{ name:'line2', type:'string' },
{ name:'city', type:'string' },
{ name:'state', type:'string'},
{ name:'zip', type:'string'}
]
});
Applicant model
Ext.define('POC.model.ApplicantModel',
{
extend: 'POC.model.Base',
requires: [
"POC.model.field.PhoneNumber",
"POC.model.AddressModel"
],
fields: [
{ name:'id', type:'string' },
{ name:'applicantName', type:'string'},
{ name:'mailingAddress', reference:'AddressModel'}
]
});
Company model
Ext.define('POC.model.CompanyInfoModel',
{
requires: [
"POC.model.field.PhoneNumber",
"POC.model.AddressModel"
],
extend: 'Ext.data.Model',
fields: [
{ name:'id', type:'string'},
{ name:'contacttype', type:'string' },
{ name:'contactname', type:'string' },
{ name:'primaryphone', type:'phonenumber' },
{ name:'secphone', type:'phonenumber' },
{ name:'primaryemail', type:'string'},
{ name:'secemail', type:'string'},
{ name:'address', reference:'AddressModel'}
]
});
Operator model
Ext.define('POC.model.AgentInfoModel',
{
extend: 'Ext.data.Model',
requires: [
"POC.model.field.PhoneNumber",
"POC.model.AddressModel"
],
fields: [
{ name:'id', type:'string'},
{ name:'agencyname', type:'string' },
{ name:'contactname', type:'string' },
{ name:'phone', type:'phonenumber' },
{ name:'code', type:'string'},
{ name:'email', type:'string'},
{ name:'address', reference:'AddressModel'}
]
});
Everything comes together in the Application Model
Ext.define('POC.model.ApplicationInfoModel',
{
requires:['POC.model.AgentInfoModel',
'POC.model.CompanyInfoModel',
'POC.model.ApplicantModel'
],
extend: 'POC.model.Base',
idProperty:'appid',
fields:[{
name:'appid',type:'string'
},
{
name:'agent',
reference:'AgentInfoModel'
},
{
name:'company',
reference:'CompanyInfoModel'
}
],
hasMany:[{
name:'applicants',
reference:'ApplicantModel'
}]
});
Associated JSON format from server
{
"success":true,
"application" :
{
"appid":"0",
"company" :
{
"id" : "0",
"contacttype" : "",
"contactname" : "",
"primaryphone" : "",
"secphone" : "",
"primaryemail" : "",
"secemail" : "",
"address" : {
"id":"114444",
"line1" : "",
"line2" : "",
"city" : "",
"state" : "",
"zip" : ""
}
},
"agent" : {
"id" : "0",
"agencyname" : "",
"contactname" : "",
"phone" : "",
"code" : "",
"email" : "",
"address" : {
"id":"11111",
"line1" : "",
"line2" : "",
"city" : "",
"state" : "",
"zip" : ""
}
},
"applicants" :
[{
"id" : "0",
"applicantName" : "",
"mailingAddress" :
{
"id":"1132323",
"line1" : "",
"line2" : "",
"city" : "",
"state" : "",
"zip" : ""
}
}, {
"id" : "1",
"applicantName" : "",
"mailingAddress" :
{
"id":"11323666",
"line1" : "",
"line2" : "",
"city" : "",
"state" : "",
"zip" : ""
}
}
]
}
}
The error I am getting ...
** W] [Ext.define] Duplicate class name "POC.model.AddressModel" specified, must be empty string Util.js: 692
[E] Ext.data.schema.Schema.addEntity (): Duplicate name of the "AddressModel" object: POC.model.AddressModel and POC.model.AddressModel
Unacceptable error: Duplicate object name "AddressModel": POC.model.AddressModel and POC.model.AddressModel **
+3
source to share
1 answer
Fixed an issue that ApplicationInfoModel had to change as shown below
Ext.define('POC.model.ApplicationInfoModel',
{
requires:['POC.model.AgentInfoModel',
'POC.model.CompanyInfoModel',
// 'POC.model.ApplicantModel'
],
extend: 'POC.model.Base',
idProperty:'appid',
fields:[{
name:'appid',type:'string'
},
{
name:'agent',
reference:'AgentInfoModel'
},
{
name:'company',
reference:'CompanyInfoModel'
}
],
hasMany:[{
name:'applicants',
model:'POC.model.ApplicantInfoModel',
}]
});
0
source to share