Results 1 to 2 of 2

Thread: associated store/model not creating instance name function

  1. #1
    Sencha User
    Join Date
    Feb 2011
    Posts
    104

    Default associated store/model not creating instance name function

    hi there!

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

    I have the models/store

    PHP Code:
    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
    PHP Code:
    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
    PHP Code:
    TypeErrorResult of expression 'currentUser.friends' [undefinedis 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!!!

  2. #2
    Sencha User
    Join Date
    Feb 2011
    Posts
    104

    Default

    *bounce*
    nothing? anybody?
    who knows it?

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •