PDA

View Full Version : associated store/model not creating instance name function



headkit
20 Jun 2011, 6:47 AM
hi there!

i have a big problem setting up an associated store/model concept.

I have the models/store



app.models.User = Ext.regModel('app.models.User', {
fields: [
{name: 'id', type: 'int'},
{name: 'userID', type: 'string'},
{name: 'userName', type: 'string'}
],

associations: [
{type: 'hasMany', model: 'app.models.Friend', name:'friends', associationKey:'friends'},
]
});

app.models.UserFriendsList = Ext.regModel('app.models.UserFriendsList', {
fields: [
{name: 'id', type: 'int'},
{name: 'userID', type: 'string'},
{name: 'userName', type: 'string'}
],

belongsTo: 'app.models.User',

associations: [
{type: 'hasMany', model: 'app.models.Friend', name: 'friend'}
]
});

app.models.Friend = Ext.regModel('app.models.Friend', {
fields: [
{name: 'id', type: 'int'},
{name: 'userID', type: 'string'},
{name: 'userName', type: 'string'}
],
belongsTo: 'app.models.UserFriendsList',
});

app.stores.userStore = new Ext.data.Store({

model: 'app.models.User',

data:[
{
"id": "01",
"userName": "Username"

"friends": [
{ "id": "02",
"userName": "Friend 1"
},
{ "id": "03",
"userName": "Friend 2"
},
]

}
]
});
I then use


var currentUser = app.stores.User.getAt(0);
console.log(currentUser);
var friends = currentUser.friends().getAt(0);
console.log(friends);
to trace some debug information about the currently loaded user.


When I use the 'associationKey'-parameter without the 'name'-parameter the trace shows that the data is fetched correctly into the data-part of the traced object 'currentUser'. But there is no function friends() to use. I only get the error


TypeError: Result of expression 'currentUser.friends' [undefined] is not a function.
When I use the 'name'-parameter without the 'associationKey'-parameter (or both parameters) the instance function friends() is created but no data is fetched into the object so I can't use it.

What is wrong with my code? Or where is my misunderstanding of concept?

THNX!!!

headkit
23 Jun 2011, 2:13 AM
*bounce*
nothing? anybody?
who knows it?