开发者

Doctrine SQL/table generation failing

I am trying to make Doctrine generate SQL from a set of models that I created earlier with a YAML schema. Using the code below which comes from the manual the output should be a set of queries.

<?php
// test.php
require_once('bootstrap.php');

try 
{
    $models = Doctrine_Core::generateSqlFromModels('models/generated');

    echo '<pre>';
    var_dump($models);
    echo '</pre>';
}
catch(Exception $e)
{
    echo $e->getMessage();
}

However, the result of this code is:

NULL

while it should return a string with the SQL queries, as said before.

I've also tried the following:

<?php
// test.php
require_once('bootstrap.php');

try {
    $result = Doctrine_Core::createTablesFromModels('models/generated');

    echo '<pre>';
    var_dump($result);
    echo '</pre>';
}
catch(Exception $e)
{
    echo $e->getMessage();
}

but that also returns:

NULL

I was not able to find the solution in the manual, the API reference or in the Doctrine core files. I hope someone here knows.

Thanks in advance.

Update: It can not be because of this (old?) bug, because I have no table name that starts with A or B.

Update: My bootstrap.php looks like this:

/**
 * Bootstrap Doctrine.php, register autoloader specify
 * configuration attributes and load models.
 */

require_once(dirname(__FILE__) . '/li开发者_JAVA技巧b/vendor/doctrine/Doctrine.php');
spl_autoload_register(array('Doctrine', 'autoload'));
$manager = Doctrine_Manager::getInstance();
$conn = Doctrine_Manager::connection('pgsql://user:pass@localhost/dbname', 'doctrine');

$manager->setAttribute(Doctrine_Core::ATTR_VALIDATE, Doctrine_Core::VALIDATE_ALL);
$manager->setAttribute(Doctrine_Core::ATTR_EXPORT, Doctrine_Core::EXPORT_ALL);
$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);

Update: I've changed the line:

$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_CONSERVATIVE);

to:

$manager->setAttribute(Doctrine_Core::ATTR_MODEL_LOADING, Doctrine_Core::MODEL_LOADING_AGGRESSIVE);

but the output of

print_r(Doctrine_Core::filterInvalidModels(Doctrine_Core::loadModels('models/generated'))) 

is still an empty array.


The problem was that the generated model names were like this:

<?php
abstract class BaseClass extends Doctrine_Record
{

}

Removing the abstract keyword did the trick. All the other Doctrine models are not using the abstract keyword, so it won't do any harm to remove it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜