Running into a problems where I have two models, Site and Evaluation, such that a Site hasMany
Evaluations and an Evaluation belongsTo a Site. I have tried both the localstorage and sql proxies, and get the same behavior.
But after I do a reload of the DOM, the hasMany association goes away:
Evaluations and an Evaluation belongsTo a Site. I have tried both the localstorage and sql proxies, and get the same behavior.
I am able to get the data associated just fine when I first do a load, as per the getData output of my instantiated Site model:
Code:
Object {id: "1c70511b-7b99-40af-9dac-bc63facc384b", remoteSiteId: 38079, siteName: null, address_id: "34563f7c-9451-4b3b-901d-126cf8f41d63", Evaluations: Array[1]…}
Address: Object
Evaluations: Array[1]
0: Object
Site: Object
category: null
comments: null
dateOfEvaluation: null
datePostedToRemote: null
evaluationType: null
evaluator_id: 265
id: "5fa845e4-7699-4fb5-91d3-83921a514bf6"
noLongerExists: null
remoteEvaluationId: 44215
site_id: "498d2ba4-a998-4090-b9a8-38003ef290d6"
__proto__: Object
length: 1
__proto__: Array[0]
address_id: "34563f7c-9451-4b3b-901d-126cf8f41d63"
id: "1c70511b-7b99-40af-9dac-bc63facc384b"
remoteSiteId: 38079
siteName: null
__proto__: Object
But after I do a reload of the DOM, the hasMany association goes away:
Code:
Object {id: "1c70511b-7b99-40af-9dac-bc63facc384b", remoteSiteId: 38079, siteName: null, address_id: "34563f7c-9451-4b3b-901d-126cf8f41d63", Evaluations: Array[0]…}
Address: Object
Evaluations: Array[0]
length: 0
__proto__: Array[0]
address_id: "34563f7c-9451-4b3b-901d-126cf8f41d63"
id: "1c70511b-7b99-40af-9dac-bc63facc384b"
remoteSiteId: 38079
siteName: null
__proto__: Object
I've searched high and low, and the closest I could find was mention of problems of storing hasMany associations in Webstorage, but this was pre-Sencha Touch 2.3 (I am using 2.3.1). As a side note, hasOne associations are just fine (my Address object is just such a thing).
Just for sanity's sake, my models are defined below:
Code:
Ext.define('EvaluateIt.model.Site', {
extend: 'EvaluateIt.model.BaseModel',
config: {
idProperty: 'id',
fields: [
{name: 'id', type: 'int'},
{name: 'remoteSiteId', type: 'int'},
{name: 'siteName', type: 'string'}, // does site have a formal name
{name: 'address_id', type: 'string'}
],
proxy: {
type: "localstorage"
},
hasMany:
[
{
model: 'EvaluateIt.model.Evaluation',
name: 'Evaluations',
primaryKey: 'id',
foreignKey: 'site_id',
associationKey: 'siteEvaluations'
}
],
hasOne: [
{
model: 'EvaluateIt.model.Address',
getterName: 'getAddress',
setterName: 'setAddress',
name: 'Address',
primaryKey: 'id',
foreignKey: 'address_id',
foreignStore: 'Addresses'
}
]
}
});
Code:
Ext.define('EvaluateIt.model.Evaluation', { extend: 'EvaluateIt.model.BaseModel',
config: {
idProperty: 'id',
fields: [
{name: 'id', type: 'int'}, // pk
{name: 'category', type: 'string'}, //used to categorize for selection of view
{name: 'remoteEvaluationId', type: 'int'}, // linking id to remote JSON
{name: 'dateOfEvaluation', type: 'date'}, // date evaluation done
{name: 'datePostedToRemote', type: 'date'}, // date successfully uploaded to remote
{name: 'evaluationType', type: 'int'}, // type of evaluation done - to be added in the future`
{name: 'site_id', type: 'string'}, // linking id for associations
{name: 'evaluator_id', type: 'int'},
{name: 'noLongerExists', type: 'boolean'}, // invalid site: nothing to evaluate!
{name: 'comments', type: 'string'} // general comments
],
proxy: {
type: "localstorage"
},
belongsTo: [
{
model: 'EvaluateIt.model.Site',
name: 'Site',
primaryKey: 'id',
foreignKey: 'site_id'
}
]
}
});
Any ideas what is going on here? Much appreciated!
Aucun commentaire:
Enregistrer un commentaire