1. #1
    Sencha User
    Join Date
    Feb 2012
    Posts
    17
    Vote Rating
    0
    jmendez88 is on a distinguished road

      0  

    Default Has Many with localstorage

    Has Many with localstorage


    Hello,

    Can I have hasMany associations with localstorage?

    For example I have two models, Recurso and Concejo.

    Concejo has belongsTo associations, and it works correctly, but Recurso has hasMany associations and when I execute miConcejo.recursos(), I receive an empty "Ext.data.Store".

    Recurso.js (Ext.data.Model)

    Code:
    Ext.define('app.model.Recurso', {
        extend: 'Ext.data.Model',
        
        config: {
                    fields: [
                        {name: "id", type: "int"},                  
                        {name: "nombre", type: "string"},                   
                        {name: "concejo_id", type: "int"},                    
                    ],
                    
                    associations: [
                                    {
                                        type: 'belongsTo', 
                                        model: 'app.model.Concejo' 
                                    }
                    ],
                    
                    proxy: {
                        type: 'localstorage',
                        id  : 'app-recursos'
                    }              
        }        
    });
    Concejo.js (Ext.data.Model)

    Code:
    Ext.define('app.model.Concejo', {
        extend: 'Ext.data.Model',
        
        requires : [ 'app.model.Recurso' ],
        
        config: {
                    fields: [
                        {name: "id", type: "int"},
                        {name: "nombre", type: "string"}
                    ],
                    
                    associations: [
                                    {
                                        type: 'hasMany',
                                        model: 'app.model.Recurso',
                                        associationKey: 'recursos',
                                    }
                    ],
                    
                    proxy: {
                        type: 'localstorage',
                        id  : 'app-concejos'
                    }
        }        
    });
    Concejos.js (Ext.data.Store)

    Code:
    Ext.define('app.store.Concejos', {
        extend: 'Ext.data.Store',
        requires: [
                    'app.model.Concejo'
        ],
        
        
        config: {
                    model: 'app.model.Concejo',
                    storeId: 'ConcejosStore',
                    autoLoad: true,
                    data: [
                            { id: "1", nombre: 'Concejo 1' },
                    { id: "2", nombre: 'Concejo 2'},
                            { id: "3", nombre: 'Concejo 3' }
            ]
        }
        
    });
    Recursos.js (Ext.data.Store)

    Code:
    Ext.define('app.store.Recursos', {
        extend: 'Ext.data.Store',
        
        requires: [
                    'app.model.Recurso'
        ],
        
        
        config: {
                    model: 'app.model.Recurso',
                    storeId: 'RecursosStore',
                    autoLoad: true,
                    sorters: [                            
                                {
                                    property: 'nombre',
                                    direction: 'ASC'
                                }
                                
                    ],
                    data: [
                            {
                                "id": "1",
                                "nombre":"Recurso 1",
                                "concejo_id": "2",
                            },
                            {
                                "id": "2",
                                "nombre":"Recurso 2",
                                "concejo_id": "1",
                            }
                    ]
        }
    });
    Thank you very much.

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Vote Rating
    750
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    You should be able to but saving associated data is not supported.
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  3. #3
    Sencha User
    Join Date
    Nov 2010
    Posts
    117
    Vote Rating
    9
    Bunchofstring will become famous soon enough

      0  

    Default


    Yours is the latest in a long list of related requests. Some brief background:

    1/20/2012 - ST team "promised" the feature in ST2 GA Release - Not delivered
    http://www.sencha.com/forum/showthre...ociated-models

    5/1/2012 - ST team promised the feature in ST2.1 - No updates for a month and a half
    http://www.sencha.com/forum/showthre...ssociated-data

    Now, we're reminded that it is not supported... with no commitment to fix the issue. So... Sencha Touch is still a great choice to build a gorgeous UI, but the data package is incomplete (my opinion), and there is no reason to think that will change any time soon. On the other hand, it's free so I can't really complain :o\

  4. #4
    Sencha User
    Join Date
    Sep 2011
    Posts
    60
    Vote Rating
    3
    janelle is on a distinguished road

      0  

    Default


    I am in the process of porting an app from ST1 to ST2. I had hasmany associations saving to local storage with no problems in version 1.

    This app is useless if I cant save the related items to local storage. When will this be coming? Is there a work around?

  5. #5
    Sencha User
    Join Date
    Oct 2011
    Location
    Germany
    Posts
    147
    Vote Rating
    10
    Möhre will become famous soon enough

      0  

    Default


    Quote Originally Posted by janelle View Post
    When will this be coming? Is there a work around?
    Good question.

    I am afraid it will take a while longer now that Ed Spencer (dev focused on the data package) leaves Sencha ...

  6. #6
    Sencha User
    Join Date
    Nov 2010
    Posts
    117
    Vote Rating
    9
    Bunchofstring will become famous soon enough

      0  

    Default


    This is the first I've heard that Ed is leaving. Hopefully someone else on the team can finish the good work that Ed started.

    Edit: Best wishes to Ed wherever he may be headed.
    Last edited by Bunchofstring; 18 Jun 2012 at 12:38 PM. Reason: Farewell

  7. #7
    Sencha User
    Join Date
    Mar 2012
    Posts
    47
    Vote Rating
    0
    romulus2012 is on a distinguished road

      0  

    Default What's the solution?

    What's the solution?


    Ok, so now it's clear that sencha doesn't support localstorage with has many associations. So, is there any solution or trick to manage this manually?

  8. #8
    Sencha User
    Join Date
    Oct 2011
    Location
    Germany
    Posts
    147
    Vote Rating
    10
    Möhre will become famous soon enough

      0  

  9. #9
    Sencha User kostysh's Avatar
    Join Date
    Nov 2011
    Location
    Odessa, Ukraine
    Posts
    171
    Vote Rating
    19
    kostysh will become famous soon enough kostysh will become famous soon enough

      1  

    Default


    Quote Originally Posted by mitchellsimoens View Post
    You should be able to but saving associated data is not supported.
    I think that this is not correct. We can save associated data by using separate store for association.

    http://www.sencha.com/forum/showthre...l=1#post835806

  10. #10
    Sencha User
    Join Date
    Nov 2010
    Posts
    117
    Vote Rating
    9
    Bunchofstring will become famous soon enough

      0  

    Default


    I just added a basic test harness with a few test cases at https://github.com/bunchofstring/ST2_Associations. This is my first time setting up a git repository, so I may need help with permissions if folks are willing to help work on this.
    1. ST2 library (-all-debug) and css
    2. index.html
    3. app.js
      1. Model idProperty wasn't always working as documented, so I created a new unique identifier strategy to address that issue.
      2. UI to clear localStorage and reload or just reload. The body also shows the results of three test cases I came up with.

film izle

hd film izle

film sitesi

takipci kazanma sitesi

takipci kazanma sitesi

güzel olan herşey

takipci alma sitesi

komik eğlenceli videolar