We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 35585
    • 2 Posts
    nevermindthebuzzcocks Reply #1, 13 years, 2 months ago
    When I try to execute a query after I’ve created a model I get the error: ’Could not get table name for class’. The generated SQL is missing its table name: ’SELECT `test`.`id` AS `test_id` FROM AS `test`’.

    I use this snippet of code:

    // create instance of $xpdo here ...
    echo $o=($xpdo->connect()) ? ’Connected’ : ’Not Connected’; //Connected
    $xpdo->addPackage(’modx’, dirname(XPDO_CORE_PATH) . ’/model/’, ’’);
    $xpdo->setDebug(true);

    $manager= $xpdo->getManager();
    $generator= $manager->getGenerator();
    $package= ’modx’;

    include_once(dirname(XPDO_CORE_PATH).’/model/’.$package.’/test.class.php’);
    include_once(dirname(XPDO_CORE_PATH).’/model/’.$package.’/mysql/test.class.php’);
    include_once(dirname(XPDO_CORE_PATH).’/model/’.$package.’/mysql/test.map.inc.php’);

    $query = $xpdo->newQuery(’test’);
    $query->prepare();
    $xpdo->log(xPDO::LOG_LEVEL_DEBUG, $query->toSql());

    test.map.inc.php =>

    $xpdo_meta_map[’Test’]= array (
    ’package’ => ’modx’,
    ’version’ => ’1.1’,
    ’table’ => ’test’,
    ’fields’ =>
    array (
    ’name’ => NULL,
    ),
    ’fieldMeta’ =>
    array (
    ’name’ =>
    array (
    ’dbtype’ => ’varchar’,
    ’precision’ => ’45’,
    ’phptype’ => ’string’,
    ’null’ => false,
    ),
    ),
    );

    The schema =>

    <?xml version="1.0" encoding="UTF-8"?>
    <model package="modx" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
    <object class="Test" table="test" extends="xPDOSimpleObject">
    <field key="name" dbtype="varchar" precision="45" phptype="string" null="false" />
    </object>
    </model>

      • 35585
      • 2 Posts
      nevermindthebuzzcocks Reply #2, 13 years, 2 months ago
      I should have used $xpdo->setPackage smiley...
        • 34020
        • 18 Posts
        Thank you so much for posting the solution! I've just spent 20 hours troubleshooting a similar issue, but I never received any errors... the queries just didn't work. Using setPackage instead of addPackage was all it took. smiley