1. #11
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default


    tried this also - didn't work for me...

  2. #12
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default


    Quote Originally Posted by JRS View Post
    I'm still struggling with it. Glad to hear it does work. I'll go back to sencha examples to see if I can get those working. Not sure OP - has it working or not.

    For now I am using a work around where I manually set
    record.data.asocdata = record.raw.asocdata
    Hi,

    Now Quite exasperated! - I remember this problem in Sencha 1.x and having to do the same thing.
    I ended up removing all the associations from the models (both sides - 'has many' and 'belongs to' ) and as suggested in 'JRS' post copying the raw data to the model/store data - crazy stuff!

    e.g.

    Code:
    callback: function (records, operation, success) {
    
    
                    console.log('raw');
                    console.log(records[0].raw);
    
    
                    // copy raw to data as sencha model load with association for nested JSON doesnt work
                    records[0].data = records[0].raw
    
    
                    console.log('records');
                    console.log(records);

  3. #13
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default Comment

    Comment


    Hi,


    It seems there some issues with the models and associations not working with even simple nested data examples - these issues have been around in the posts since Sencha 1.x.

    Or perhaps its a documentation issue and we are trying to use the models as was not intended?

    My understanding is that it is effectively a client side object structure (in Sencha Javascript) for data retrieved from the server e.g. a simple db entity framework on the client.
    Have I got this wrong?

    It would be great if someone from Sencha could provide some guidance on how this is supposed to work e.g. is nested JSON data supported - if so how?

    Also there seems to be lots of different posts out there on the correct plumbing for models to make this work.
    e.g.
    - the need for associationKeys in various formats - or not
    - needing to have an 'id' field on every model - or not
    - needing to relate the models with foreign keys with the same model name / naming std as the parent - or not.

    NOTE: this last requirement seems strange to me given the relationships are defined by the nesting in the JSON format e.g. why would you need to do this as JSON defines parent/child relationships for you via the nature of its format.

    Anyway END RANT - if anyone can point me to a definitive resource on how this all hangs together (for an enterprise scenario e.g. not simple examples we have now ) then mea culpa.

  4. #14
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    I am sorry ,the records in callback is array, not collection.
    Code:
    callback:function(records,operation, success){
        var user0,user0_role0,user0_message0;
        //user0 = records.getAt(0);
        user0 = records[0];
        user0_role0 = user0.roles().getAt(0);
        user0_message0 = user0.messages().getAt(0);
        //for each user0 messages
        user0.messages().each(function(message){
             // do something here
        })
    }
    I write English by translator.

  5. #15
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default


    thanks - doesnt do anything unfortunately e.g. no nested data returned..and never reaches '4' below...see attachment also
    Code:
     userStore.load({
                callback: function (records, operation, success) {
                    console.log('1');
                    //user0 = records.getAt(0);
                    user0 = records[0];
                    user0_role0 = user0.roles().getAt(0);
                    user0_message0 = user0.messages().getAt(0);
                    console.log('2');
                    console.log(user0);
                    console.log('2.1');
                    console.log(user0_role0);
                    console.log('2.2');
                    console.log(user0_message0);
                    console.log('3');
                    //for each user0 messages
                    user0.messages().each(function (message) {
                        // do something here
                        console.log('4');
                        console.log(message);
                    })
    Attached Files

  6. #16
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    I create a demo ,everything works fine.(st2.1)
    Attached Files
    I write English by translator.

  7. #17
    Sencha User
    Join Date
    Nov 2012
    Location
    Netherlands
    Posts
    50
    Answers
    6
    Vote Rating
    1
    eastlander is on a distinguished road

      0  

    Default


    It seems like the variable records is already your user. As I can see this class also contains a rolesStore and messagesStore so user0.Roles() should return all the roles and user0.Messages() should return the messages.

  8. #18
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default


    Quote Originally Posted by haduki View Post
    I create a demo ,everything works fine.(st2.1)
    Hi haduki,

    thanks!

    yes now working (sort of - although there seem to be some strange ways I need to access things - do things - see my questions below)
    It turns out these are the magic lines (in red below) that make everything work , and also how I was accessing the 'roles()' method when there was only an empty role array passed... I have some questions below to aid in my understanding of how this should all hang together.

    Code:
     {model: 'HMMobileCharts.model.Role', name: 'roles', associationKey: 'Roles' }
             , { model: 'HMMobileCharts.model.Message', name: 'messages', associationKey: 'Messages' }
    My questions:

    1/
    what does the 'associationKey' do and what is the rules around this - naming etc.
    Also I saw this tweet https://twitter.com/SenchaMitch/stat...94918567976962
    but don't understand what this means.
    2/
    It turns out I have to access my fields like this (below) - always using the keyword 'data' - is this correct?
    Code:
    var user = records[0];
                    console.log(user.data.FirstName);
                    console.log(user.data.LastName);
                    console.log(user.data.IsAuthenticated);
    and for nested:
    Code:
    messages.getAt(0).data.MessageStr
    3/
    if the JSON returns an empty role array e.g. "Roles":[] then it seems
    Code:
    user.roles()....
    return nothing - is the best way to test for this having values as follows? -
    Code:
    if(roles.data.length>0)

    4/
    instead of seeing (as I would of expected) the 'user' object have nested objects arrays for roles and messages (as shown in the 'raw' value) they appear to come accross in a 'messageStore' and 'userStore' - does someone have an explanation of this and/or can point me to some doco on this?

    ..

    It would be great if there was a very clear and detailed guide somewhere about how all this works/hangs together with more than just trivial examples - this would save a lot of time and effort.
    If anyone knows of such a thing I would be keen to know.
    thanks to everyone who responded!

    ..

  9. #19
    Sencha User
    Join Date
    Apr 2010
    Location
    China
    Posts
    227
    Answers
    64
    Vote Rating
    20
    haduki will become famous soon enough haduki will become famous soon enough

      0  

    Default


    1/ sorry for my poor english,i cant say long sentence.
    you just need to know:
    Code:
    dataFromServer={users:[{ roles:[{id:'role_1'}]}]} 
    associationKey should be 'roles'
    
    dataFromServer={users:[{ myRoles:[{id:'role_1'}]}]}
     associationKey should be 'myRoles'
    
    dataFromServer={
       users:[
          { 
             id:'user_1',
             extraData:{roles:[{id:'role_1'}]},
             lastName:'FirstName',
             ...
          }
       ]
    }
    associationKey should be 'extraData.roles'
    2/ no.
    Code:
    user.get('FirstName');
    user.get('LastName');
    user.messages().getAt(0).get('MessageStr')
    3/
    Code:
    if(user.roles().getCount()===0)
    4/
    it is let you control the entity easily.
    if the roles and messages are read-only in your application,you no need to use association.

    http://docs.sencha.com/touch/2-1/#!/...on.Association
    http://docs.sencha.com/touch/2-1/#!/guide/models
    http://docs.sencha.com/touch/2-1/#!/guide/stores
    I write English by translator.

  10. #20
    Sencha Premium Member
    Join Date
    Feb 2012
    Posts
    84
    Answers
    4
    Vote Rating
    1
    busaware1 is on a distinguished road

      0  

    Default


    thanks again for your reply.
    the std documentation is not very clear on all of these aspects
    but thanks anyway!

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