We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 1778
    • 659 Posts
    Hello

    I feel a bit stupid today, (and probably a lot of tired), my problem is pretty basic and I know I solved it in the past, but I can’t remember how ... (tired I said).

    I have a CMP with some grids to display (and update etc) custom datas from custom tables... All is fine when the primary key in my custom tables is ID (ie whem my Object extends xPDOSimpleObject, where the primary key is auto-generated with the key of ’id’).

    But with another primay_key defined I can’t display datas in my grid;

    2 examples :

    tables schemas
    //TABLE 1 : Object extends xPDOObject (simplified )
    
        <object class="compThing" table="comp_things" extends="xPDOObject" >
            <field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
            <field key="description" dbtype="text" phptype="string" null="true" default="" />
    
            <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE">
                <column key="name" length="" collation="A" null="false" />
            </index>
        </object>
    
    //TABLE 2 : Object extends xPDOSimpleObject (simplified )
    
        <object class="compOtherThing" table="comp_other_things" extends="xPDOSimpleObject" >
            <field key="nameOT" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
            <field key="description" dbtype="text" phptype="string" null="true" default="" />
        </object>
    
    


    The Grid definition for table1

    Ultravox.grid.Things = function(config){
        config = config || {};
        Ext.applyIf(config,{
            id: 'comp-grid-things',
            url: Comp.config.connectorUrl,
            baseParams:{
                action: 'mgr/utils/things/getList'
            },
            fields: ['name', 'description'],
            paging: true,
            remoteSort: true,
            anchor: '97%',
            autoExpandColumn: 'description',
            primaryKey: 'name',
            columns: [{
                header: _('name'),
                dataIndex: 'name',
                sortable: true,
                width: 80
            },{
                header: _('description'),
                dataIndex: 'description',
                sortable: true
            }]
    
        });
        Comp.grid.Things.superclass.constructor.call(this,config);
    };
    Ext.extend(Comp.grid.Things, MODx.grid.Grid);
    Ext.reg('comp-grid-things', Comp.grid.things);
    


    and the processor getList
    /* setup default properties */
    $isLimit = empty($scriptProperties['limit']);
    $start = $modx->getOption('start',$scriptProperties,0);
    $limit = 0;
    $sort = $modx->getOption('sort',$scriptProperties,'name');
    $dir = $modx->getOption('dir',$scriptProperties,'ASC');
    
    
    // build query */
    $c = $modx->newQuery('compThing');
    
    
    
    $things = $modx->getCollection('compThing',$c);
    $count = $modx->getCount('compThing',$c);
    // iterate
    $list = array();
    foreach ($things as $thing) {
        $thingArray = $thing->toArray();
        $list[]= $thingArray;
    }
    return $this->outputArray($list,$count);
    
    


    With this code, the grid is shown but no data (instead of, I have ’no data to display’, but datas are in the table) and the MODx Error log says

    [2011-08-19 15:29:35] (ERROR @ /3PC/Ultravox/assets/components/ultravox/connector.php) Error 42S22 executing statement: 
    Array
    (
        [0] => 42S22
        [1] => 1054
        [2] => Unknown column 'compThing.id' in 'field list'
    )
    
    


    Do the same code with the table 2, (where I don’t specify " primaryKey: ’name’ ", and add the field ’id’ of course) the datas are shown. (automatic primary key is ’id’ then).

    I probably forgot something basic in my code, but I can’t figure out what...

    I have alos a ’create button’ with this grid, it calls a create window, and that’s part works fine (create and save the new data in the table), so I suppose the problem is somewhere in my getList.php file, but I can’t see where..

    Thanks for your help

    [EDIT & SOLVED] : There was probably a problem with the table... Rebuild my schema, drop the ’culprit’ table and re-create it via ’createObjectContainer(’cmpThing’)’, and all is fine now...