PDA

View Full Version : belongsTo association



rez
17 Jun 2011, 12:25 AM
I cannot seem to get this to work properly with my models, for the following does this look correct?



app.models.User = Ext.regModel("app.models.User", {
idProperty: '_id',
fields: [
{name: "_id", type: "string"},
{name: "name", type: "string"},
...
...

});



-----------


app.models.Post = Ext.regModel("app.models.Post", {

fields: [

{name: '_id', type: 'string'},
{name: 'body', type: 'string'},
{name: 'created_at', type: 'string'},
{name: 'updated_at', type: 'string'},
{name: 'user_id', type: 'string'},
]

associations: [ { type: 'belongsTo', model: 'app.models.User', foreignKey: 'user_id', primaryKey: '_id' }

});


]


as a workaround I am injecting the associated data I need in the controller :/

eg.


Ext.each(record.data.posts , function(post, index) {

post.user_name = app.stores.users.getById(post.user_id).data.name

});




TIA.