1

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__) . '/lib/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.

Evert
  • 376
  • 2
  • 10
  • Whats the output of: `print_r(Doctrine_Core::filterInvalidModels(Doctrine_Core::loadModels('models/generated'));` Also have you tried use the absolute path? – prodigitalson Sep 19 '10 at 18:30
  • Thanks for your comment! The output is: Array ( ), so it seems that the models are valid. Absolute path (/var/www/vhosts/ etc.) gives the same result as the relative path. – Evert Sep 19 '10 at 18:36
  • Actually if it found models and filtered them appropriately you have all the valid models as path or class names (i forget which) in that array - meaning that in your case `Doctrine_Core::loadModels` isnt finding the models or they are all invalid. Whats your bootstrap look like? – prodigitalson Sep 19 '10 at 20:02
  • I've updated my post, bootstrap.php is at the bottom. – Evert Sep 19 '10 at 20:23
  • try specing `Doctrine_Core::MODEL_LOADING_AGGRESSIVE` and see it it makes a difference. – prodigitalson Sep 19 '10 at 22:21
  • Have you tried using `Doctrine::loadModels`? Some posts here on SO seem to have problems with non-Doctrine autoloading (altough your autoloader may do the same thing). – DrColossos Sep 20 '10 at 08:05
  • @DrColossos: Thanks! Yes, I've tried using loadModels(), but that function returns an empty array too, so it's more likely that the models are not found. But thanks anyway! – Evert Sep 20 '10 at 12:03

1 Answers1

0

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.

Evert
  • 376
  • 2
  • 10