Thank you for reporting this bug. We will make it our priority to review this report.
  1. #1
    Sencha Premium Member
    Join Date
    Mar 2008
    Posts
    92
    Vote Rating
    1
    kveeiv is on a distinguished road

      0  

    Exclamation [FIXED][BUG][PR 3] Names of model associations automatic functions collide

    [FIXED][BUG][PR 3] Names of model associations automatic functions collide


    If you have an association in your data that has the same name as one of the members of the base record object, the naming will collide and the automatically generated functions will not be created, causing cascading failures. Example:

    Code:
    Ext.onReady(function() {
    
    	var failData = [{
    		id: 'parent1',
    		role: 'owner',
    		fields: [{
    			id: 'child1',
    			type: 'A'
    		},{
    			id: 'child2',
    			type: 'A'
    		}]
    	}];
    
    	Ext.regModel('TestChildren', {
    		idProperty: 'id',
    		fields: [
    			{name:'id', type:'string'},
    			{name:'type', type:'string'}
    		]
    	});
    
    	Ext.regModel('TestParent', {
    		idProperty: 'id',
    		fields: [{
    			name:'id', type:'string'
    		},{
    			name:'role', type:'string'
    		}],
    		hasMany: [{
    			model: 'TestChildren',
    			name: 'fields'
    		}]
    	});
    
    	var store = new Ext.data.Store({
    		model: 'TestParent',
    		autoLoad: true,
    		proxy: {
    			type: 'memory',
    			reader: {
    				type: 'json',
    				root: 'records'
    			}
    		},
    		data: {
    			records: failData
    		}
    	});
    
    });
    This data will not load because of the child being named "fields". It looks like the record[associationName]() function does not get created in this case, so when the readAssociated() function tries to retrieve the store for that association, it pukes (ext-all-debug.js:23123).

    Changing the name of the field to something that doesn't collide avoids this issue. For example, in the test above replace 'fields' in the failData object and 'fields' in the hasMany definition for TestParent with 'children'. Sometimes, such as when loading data from a third-party service, we don't have control over the data structure that we are loading.

  2. #2
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,917
    Vote Rating
    630
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    I don't really see what we can do here, the same could apply to numerous points in the library.

    Code:
    Ext.onReady(function(){
        var ct = Ext.create('Ext.container.Container', {
            render: true,
            items: {
                html: 'Foo'
            }
        });
        ct.render(document.body); //explode
    });
    The case you've posted is more insidious because these properties/methods get created on the fly, but it's essentially the same concept.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  3. #3
    Sencha Premium Member
    Join Date
    Mar 2008
    Posts
    92
    Vote Rating
    1
    kveeiv is on a distinguished road

      0  

    Default


    I hadn't really considered the parallels to the overriding functionality, probably as you said because the functions are created on the fly so its not as obvious that it would be happening, and also because (as was my case) these definitions were created dynamically based on 3rd party data. Its more obvious - and I think less likely - when an override is defined explicitly on a created object as it is in your example.

    With consideration for that, perhaps the associations could have implemented the "mapping" configuration that is implemented for fields. This would provide a few benefits:

    Code:
    ...
    associations: [
       // Specifically avoid particular association name collisions
       { type: 'hasMany', name: 'children', mapping: 'fields'},
       // Model.fields() => Model.children()
    
       // Make dumb source-data relationship names easier to use on the client side
       { type: 'hasMany', name: 'betterName', mapping: 'other_people_name_things_dumbly' },
       // Model.other_people_name_things_dumbly() => Model.betterName()
    
       // Or even (probably unwisely) hijack the cleverness of the store accessor name creation
       { type: 'hasMany', name: 'getFieldStore', mapping: 'fields' }
       // Model.fields() => Model.getFieldStore()
    ]
    ...

  4. #4
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,917
    Vote Rating
    630
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Yeah, after I posted I was looking at a few other things in the data package and I had a similar thought, a mapping could be useful here.
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

  5. #5
    Sencha - Ext JS Dev Team evant's Avatar
    Join Date
    Apr 2007
    Location
    Sydney, Australia
    Posts
    16,917
    Vote Rating
    630
    evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute evant has a reputation beyond repute

      0  

    Default


    Upon review this is already possible:

    Code:
    Ext.require('Ext.data.*');
    
    Ext.onReady(function(){
        Ext.onReady(function(){
        
            var failData = [{
                id: 'parent1',
                role: 'owner',
                fields: [{
                    id: 'child1',
                    type: 'A'
                }, {
                    id: 'child2',
                    type: 'A'
                }]
            }];
            
            Ext.regModel('TestChildren', {
                idProperty: 'id',
                fields: [{
                    name: 'id',
                    type: 'string'
                }, {
                    name: 'type',
                    type: 'string'
                }]
            });
            
            Ext.regModel('TestParent', {
                idProperty: 'id',
                fields: [{
                    name: 'id',
                    type: 'string'
                }, {
                    name: 'role',
                    type: 'string'
                }],
                hasMany: [{
                    model: 'TestChildren',
                    name: 'children',
                    associationKey: 'fields'
                }]
            });
            
            var store = new Ext.data.Store({
                model: 'TestParent',
                autoLoad: true,
                proxy: {
                    type: 'memory',
                    reader: {
                        type: 'json',
                        root: 'records'
                    }
                },
                data: {
                    records: failData
                }
            });
            
            console.log(store.first().children().getCount());
            
        });
    });
    Evan Trimboli
    Sencha Developer
    Twitter - @evantrimboli
    Don't be afraid of the source code!

Similar Threads

  1. [FIXED-583] nested xml / complex xml, cant get associations to work
    By Nostromo in forum Sencha Touch 1.x: Bugs
    Replies: 18
    Last Post: 20 Mar 2012, 2:12 PM
  2. Override functions in my Model and call the base class?
    By wizkid in forum Ext: Discussion
    Replies: 5
    Last Post: 5 Mar 2011, 2:27 PM
  3. model names not showing in Tree (source included)
    By british_trader in forum Ext GWT: Discussion
    Replies: 2
    Last Post: 21 May 2010, 6:30 AM
  4. Check model property names on bind
    By sdc in forum Community Discussion
    Replies: 4
    Last Post: 22 Dec 2008, 11:39 PM

Thread Participants: 1