1. #1
    Sencha User
    Join Date
    Apr 2011
    Posts
    4
    Vote Rating
    0
    Marco Struck is on a distinguished road

      0  

    Default My simple data example with associations does not work. Why not?

    My simple data example with associations does not work. Why not?


    From my point of view I build the simplest way of model with associations in ExtJS.
    Model: Post --hasOne--> User
    What I did:
    • Using a memory proxy
    • Followed the rule: Proxy in Model
    • Load a post object by Post.load(...).
    But when I try to get the user object, it is not right loaded:
    (Here the full source: http://jsfiddle.net/7XRw4/4/)

    PHP Code:
        Ext.define('Post', {
            
    extend'Ext.data.Model',
            
    fields: ['user_id''content'],
            
    hasOne'User',
            
    proxy: {
                
    type'memory',
                
    data: {
                    
    posts: [
                        {
    id:1user_id:1content:'foo'},
                        {
    id:2user_id:1content:'bar'}
                    ]
                },
                
    reader: {
                    
    type'json',
                    
    root'posts'
                
    }
            }
        });
        
        
        
    Ext.define('User', {
            
    extend'Ext.data.Model',
            
    fields: ['name'],
            
    proxy: {
                
    type'memory',
                
    data: {
                    
    users: [
                        {
    id:1name:'hans'},
                        {
    id:2name:'klaus'}
                    ]
                },
                
    reader: {
                    
    type'json',
                    
    root'users'
                
    }
            }
        });
        
        
    Ext.onReady(function() {
            
    console.log("Ext.onReady() invoked...");
        
            
    Post.load('1', {
                
    success: function(recordoperation) {
                    
    thePost record;
        
                    
    console.log('thePost:'thePost);
                    
    theUser thePost.getUser();
                    
    console.log('theUser:'theUser);
                    
                    
    alert('The user name: ' theUser.get('name'));
                    
    // The user object will not be right loaded! Why?
                
    }
            });
            
        }); 

  2. #2
    Sencha - Community Support Team sword-it's Avatar
    Join Date
    May 2012
    Location
    Istanbul
    Posts
    1,333
    Vote Rating
    85
    sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough sword-it is a jewel in the rough

      0  

    Default


    Hi Marco,

    You can simply put hasOne config under association config like-
    Code:
    Ext.define('Post', {
            extend: 'Ext.data.Model',
            fields: ['user_id', 'content'],
            associations: [{ type: 'hasOne', model: 'User' }],
            proxy: {
                type: 'memory',
                data: {
                    posts: [
                        {id:1, user_id:1, content:'foo'},
                        {id:2, user_id:1, content:'bar'}
                    ]
                },
                reader: {
                    type: 'json',
                    root: 'posts'
                }
            }
        });
    For more info see - http://docs.sencha.com/ext-js/4-1/#!...ciation.HasOne
    sword-it.com, Sencha Developer House in Turkey - Istanbul University Technopark Suite 204.

  3. #3
    Sencha User
    Join Date
    Apr 2011
    Posts
    4
    Vote Rating
    0
    Marco Struck is on a distinguished road

      0  

    Default


    Hi sword-it, thanks for the tip.
    But it does not solve my problem.

    Another hint?

    Regards,
    Marco

  4. #4
    Sencha User
    Join Date
    Apr 2011
    Posts
    4
    Vote Rating
    0
    Marco Struck is on a distinguished road

      0  

    Default


    Hey guys, that is all? Can not believe.
    Marco

  5. #5
    Sencha User
    Join Date
    Apr 2011
    Posts
    4
    Vote Rating
    0
    Marco Struck is on a distinguished road

      0  

    Default


    Is this a vote generator?

  6. #6
    Sencha - Sales Team daniel.gallo's Avatar
    Join Date
    Apr 2009
    Location
    Bath, UK
    Posts
    50
    Vote Rating
    8
    daniel.gallo will become famous soon enough

      1  

    Default


    Hi Marco,

    When doing "getUser", this is asynchronous so requires a callback function to get at the user instance. For example (from the documentation here: http://docs.sencha.com/ext-js/4-1/#!/guide/data):

    Code:
    post.getUser(function(user) {
        console.log('Just got the user reference from the post: ' + user.get('name'))
    });
    Hope that helps.
    Daniel Gallo
    Sales Engineer EMEA
    Sencha UK Ltd

Thread Participants: 2

Tags for this Thread

Turkiyenin en sevilen filmlerinin yer aldigi xnxx internet sitemiz olan ve porn sex tarzi bir site olan mobil porno izle sitemiz gercekten dillere destan bir durumda herkesin sevdigi bir site olarak tarihe gececege benziyor. Sitenin en belirgin ozelliklerinden birisi de Turkiyede gercekten kaliteli ve muntazam, duzenli porno izle siteleri olmamasidir. Bu yuzden iste. Ayrica en net goruntu kalitesine sahip adresinde yayinlanmaktadir. Mesela diğer sitelerimizden bahsedecek olursak, en iyi hd porno video arşivine sahip bir siteyiz. "The Best anal porn videos and slut anus, big asses movies set..." hd porno faketaxi