karan
19 Sep 2012, 4:24 AM
Model is not loading the related association I've defined. I've tried everything but the Images object defined as association just doesn't load into a separate model. The code (partial, this is a full MVC app) I'm using is given below. Any pointers would be very helpful, specially how to debug this sucker as there are no errors at all.
// Besides loading the data from the server, I tried the following from chrome's console and still the image association is not loaded. The listing object populates fine but the related images object just doesn't.
var listing = new MyApp.model.Listing({
"lid": 100350565,
"s": "active",
"uid": 5740991,
"caid": 68903982,
"stl": ["Shabby Chic", "Rustic"],
"desc": "A beautiful distressed natural wood finish cheese box.",
"Images": [{
"lmid": 338991916,
"isbw": false,
"cts": 1337642744,
"lid": 100350565,
"rk": 1,
"u75": "http://img0.static.com/000/0/5273564/il_75x75.338991916.jpg",
"u170": "http://img0.static.com/000/0/5273564/il_170x135.338991916.jpg",
"u570": "http://img0.static.com/000/0/5273564/il_570xN.338991916.jpg",
"uful": "http://img0.static.com/000/0/5273564/il_fullxfull.338991916.jpg",
"uh": 1000,
"uw": 1500
}, {
"lmid": 338867087,
"isbw": false,
"cts": 1337642744,
"lid": 100350565,
"rk": 2,
"u75": "http://img3.static.com/000/0/5273564/il_75x75.338867087.jpg",
"u170": "http://img3.static.com/000/0/5273564/il_170x135.338867087.jpg",
"u570": "http://img3.static.com/000/0/5273564/il_570xN.338867087.jpg",
"uful": "http://img3.static.com/000/0/5273564/il_fullxfull.338867087.jpg",
"uh": 1500,
"uw": 1000
}]})
var types = Ext.data.Types;
Ext.define('MyApp.model.Listing',{
extend: 'Ext.data.Model',
requires: 'MyApp.model.Image',
fields :[
{name: 'lid', type: 'string', convert: null}, // Listing ID
{name: 's', type: 'string', convert: null}, //
{name: 'uid', type: 'string', convert: null}, //
{name: 'caid', type: 'string', convert: null}, //
{name: 'stl', type: 'string', convert: null}, //
{name: 'desc', type: 'string', convert: null} //
// {name: 'Images', type: 'string', convert: null},
, associations :[
{type: 'hasMany', model: 'Image', name: 'Images', associationKey: 'Images', primaryKey: 'lmid', foreignKey:'lid' }
]
, proxy: {
type: 'ajax',
url: 'assets/data/listings.json',
reader: {
type: 'json',
root: 'results'
}
}
});
Ext.define('MyApp.model.Image',{
extend: 'Ext.data.Model',
fields :[
{name: 'lid', type: 'string', convert: null}, // Listing ID
{name: 'lmid', type: 'string', convert: null}, // Listing Image ID - PK
{name: 'isbw', type: 'string', convert: null}, // Is black & W
{name: 'cts', type: 'string', convert: null}, // Creation ts
{name: 'rk', type: 'string', convert: null}, // rank
{name: 'u75', type: 'string', convert: null}, // url 75
{name: 'u170', type: 'string', convert: null}, // u 170
{name: 'u570', type: 'string', convert: null}, //
{name: 'uful', type: 'string', convert: null}, //
{name: 'uh', type: 'string', convert: null}, // full height
{name: 'uw', type: 'string', convert: null} // full width
],
associations: [{ type: 'belongsTo', model: 'Listing', primaryKey:'lmid',foreignKey:'lid' } ]
});
// Besides loading the data from the server, I tried the following from chrome's console and still the image association is not loaded. The listing object populates fine but the related images object just doesn't.
var listing = new MyApp.model.Listing({
"lid": 100350565,
"s": "active",
"uid": 5740991,
"caid": 68903982,
"stl": ["Shabby Chic", "Rustic"],
"desc": "A beautiful distressed natural wood finish cheese box.",
"Images": [{
"lmid": 338991916,
"isbw": false,
"cts": 1337642744,
"lid": 100350565,
"rk": 1,
"u75": "http://img0.static.com/000/0/5273564/il_75x75.338991916.jpg",
"u170": "http://img0.static.com/000/0/5273564/il_170x135.338991916.jpg",
"u570": "http://img0.static.com/000/0/5273564/il_570xN.338991916.jpg",
"uful": "http://img0.static.com/000/0/5273564/il_fullxfull.338991916.jpg",
"uh": 1000,
"uw": 1500
}, {
"lmid": 338867087,
"isbw": false,
"cts": 1337642744,
"lid": 100350565,
"rk": 2,
"u75": "http://img3.static.com/000/0/5273564/il_75x75.338867087.jpg",
"u170": "http://img3.static.com/000/0/5273564/il_170x135.338867087.jpg",
"u570": "http://img3.static.com/000/0/5273564/il_570xN.338867087.jpg",
"uful": "http://img3.static.com/000/0/5273564/il_fullxfull.338867087.jpg",
"uh": 1500,
"uw": 1000
}]})
var types = Ext.data.Types;
Ext.define('MyApp.model.Listing',{
extend: 'Ext.data.Model',
requires: 'MyApp.model.Image',
fields :[
{name: 'lid', type: 'string', convert: null}, // Listing ID
{name: 's', type: 'string', convert: null}, //
{name: 'uid', type: 'string', convert: null}, //
{name: 'caid', type: 'string', convert: null}, //
{name: 'stl', type: 'string', convert: null}, //
{name: 'desc', type: 'string', convert: null} //
// {name: 'Images', type: 'string', convert: null},
, associations :[
{type: 'hasMany', model: 'Image', name: 'Images', associationKey: 'Images', primaryKey: 'lmid', foreignKey:'lid' }
]
, proxy: {
type: 'ajax',
url: 'assets/data/listings.json',
reader: {
type: 'json',
root: 'results'
}
}
});
Ext.define('MyApp.model.Image',{
extend: 'Ext.data.Model',
fields :[
{name: 'lid', type: 'string', convert: null}, // Listing ID
{name: 'lmid', type: 'string', convert: null}, // Listing Image ID - PK
{name: 'isbw', type: 'string', convert: null}, // Is black & W
{name: 'cts', type: 'string', convert: null}, // Creation ts
{name: 'rk', type: 'string', convert: null}, // rank
{name: 'u75', type: 'string', convert: null}, // url 75
{name: 'u170', type: 'string', convert: null}, // u 170
{name: 'u570', type: 'string', convert: null}, //
{name: 'uful', type: 'string', convert: null}, //
{name: 'uh', type: 'string', convert: null}, // full height
{name: 'uw', type: 'string', convert: null} // full width
],
associations: [{ type: 'belongsTo', model: 'Listing', primaryKey:'lmid',foreignKey:'lid' } ]
});