1. #1
    Sencha User
    Join Date
    Dec 2011
    Posts
    200
    Vote Rating
    4
    dedoz is on a distinguished road

      0  

    Default Working with associated models #4 - hasOne conceptual (docs) problem #2

    Working with associated models #4 - hasOne conceptual (docs) problem #2


    Based on the previus post
    http://www.sencha.com/forum/showthread.php?184161-Working-with-associated-models-3-hasOne-conceptual-(docs)-problems

    This applies to docs for ExtJs 4.1 beta 1, beta 2 and beta 3.
    (as always excuse my bad english)
    Wrong thing #2
    Code example from the docs
    Code:
    Ext.define('Person', {
        extend: 'Ext.data.Model',
        fields: [
            { name: 'id',   type: 'int' },
            { name: 'name', type: 'string' },
            { name: 'address_id', type: 'int'}
        ]
    });
     
    Ext.define('Address', {
        extend: 'Ext.data.Model',
        fields: [
            { name: 'id',          type: 'int' },
            { name: 'number', type: 'string' },
            { name: 'street', type: 'string' },
            { name: 'city', type: 'string' },
            { name: 'zip', type: 'string' },
        ],
    // we can use the hasOne shortcut on the model to create a hasOne association
        associations: { type: 'hasOne', model: 'Address' }
    });
    This just makes no sense. Theres a person model in the example that has no association to address, and address has no association to person (address association targets to it self)

    Below in the docs says
    “In the example above we have created models for People and Addresses, and linked them together by saying that each Person has a single Address
    They are not linked! Anyway I guess (from the text) that the association (in the example code) should be defined in the person model, so an association from person targets address model.
    So the intented example was to code the relation “person has one address”. In this case the person definition is wrong also.
    If person has one address, the key that travels is person primary key. Person id travels to Address model (address model should have a person_id field) if not, if person has a address_id field then this represent what "belongs to" docs explain. So the example is all wrong.
    So example should be something like this, if they were trying to code “person has one address”
    Code:
    Ext.define('Person', {
        extend: 'Ext.data.Model',
        fields: [
            { name: 'id',   type: 'int' },
            { name: 'name', type: 'string' },
                                                                      // removed address_id field
        ],
        associations: { type: 'hasOne', model: 'Address' } // moved from address model
    });
     
    Ext.define('Address', {
        extend: 'Ext.data.Model',
        fields: [
            { name: 'id', type: 'int' },
            { name: 'person_id',  type: 'int' }, // created 
     
            { name: 'number', type: 'string' },
            { name: 'street', type: 'string' },
            { name: 'city', type: 'string' },
            { name: 'zip', type: 'string' },
        ]
    });
    I didn’t want to keep reading “has one” docs, just to not waste more time. At this point I learned to not care bout what ExtJs docs says is usally wrong or a poor description, i got used to check source code, but if in the code theres a problem then i care.
    There’s more “wrong things” (on the source code), but needs an explanation with code test case so ill create another post.

    so this correction to the example is right ? or im wrong

  2. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    35,704
    Vote Rating
    751
    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


    Once again, if you believe you have found a bug, post int he bugs forum.
    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.

Thread Participants: 1

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