1. #1
    Sencha User
    Join Date
    Sep 2012
    Posts
    83
    Vote Rating
    5
    mpost is on a distinguished road

      0  

    Default Polymorphic model?

    Polymorphic model?


    I have a textbook case of polymorphism: my web server is going to return a shape which could be a circle (center point + radius), rectangle (upper left/lower right), polygon (arbitrary list of points), etc. What's the best way to handle this from a model standpoint?

    I'm using an ajax proxy. One solution is to define a model object which is the union of all fields and includes a string that identifies the shape type. It would work ... but I was hoping ExtJS offered a better solution. (I just don't see how to choose a different model based on the server's response.)

  2. #2
    Sencha User Stormseeker's Avatar
    Join Date
    Jan 2010
    Location
    Evanston, Illinois
    Posts
    55
    Vote Rating
    1
    Stormseeker is on a distinguished road

      0  

    Default I think something like this should work

    I think something like this should work


    Code:
    Ext.define('Sample.model.Shape', {
        extend        : 'Ext.data.Model',
    
        fields        : [
            {name: 'id',                                 type: 'int'},
            {name: 'name',                             type: 'string'}
        ]
    });
    
    Ext.define('Sample.model.Circle', {
        extend        : 'Sample.model.Shape',
    
        fields        : [
            {name: 'radius',                             type: 'float'}
        ]
    });

  3. #3
    Sencha Premium Member vadimv's Avatar
    Join Date
    Sep 2010
    Location
    Chisinau, Moldova
    Posts
    642
    Vote Rating
    25
    vadimv will become famous soon enough vadimv will become famous soon enough

      0  

    Default


    Probably I would try to use extjs's associations in direction of polymorphic associations, by default is nothing implemented, and probably you will have to extend the reader in order to create the right model based on server response.....could be an idea which worths to try.
    I didn't look well, to comment if their implementations are good or not, but you may get some inspirations from this guys:
    http://extjs-tutorials.blogspot.com/...-subclass.html
    https://github.com/opennode/opennode...&-Partitioning

  4. #4
    Sencha User
    Join Date
    Nov 2012
    Location
    uk
    Posts
    7
    Vote Rating
    0
    Michael H is on a distinguished road

      0  

    Default


    Quote Originally Posted by vadimv View Post
    Probably I would try to use extjs's associations in direction of polymorphic associations, by default is nothing implemented, and probably you will have to extend the reader in order to create the right model based on server response.....could be an idea which worths to try.
    I didn't look well to comment if their implementation are good or not, but you may get some inspirations from this guys:
    http://extjs-tutorials.blogspot.com/...-subclass.html
    https://github.com/opennode/opennode...&-Partitioning
    nice tutorial to read . i liked it very much....
    .

  5. #5
    Sencha User
    Join Date
    Sep 2012
    Posts
    83
    Vote Rating
    5
    mpost is on a distinguished road

      0  

    Default


    Thanks vadimv, that's pretty much what I was looking for. It's a shame that ExtJS doesn't offer this functionality natively.

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