Doctrine 1
  1. Doctrine 1
  2. DC-885

Building schema doesn't work when tables have cross database foreign keys (MySQL).

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.3
    • Fix Version/s: None
    • Component/s: Schema Files
    • Labels:
      None
    • Environment:
      Windows XP SP3, Apache 2, PHP 5.3, MySQL 5.1.36, Symfony 1.4.8.

      Description

      When building schema using the doctrine:build-schena task from multiple databases used in our project, the import process end up with a "missing classname" error without building the schema.yml file.

      This seems to be caused by the fact that the tables contained in the databases contain foreign keys referencing the other databases tables pks.

      As an example we have :

      • A main database (call it portal) that contains user's informations, and many other things.
      • a second database that contains business informations with some tables refererecing users informations contained in the main database.

      When generating the schema, and specifically on the second database step, there are no informations found for the primary keys contained main database.

      Digging in the import process, it seems that the issue comes from the fact that the Doctrine_Import.importSchema function creates a new definition array instance for every database encountered in the databases.yml.

      The correction found for this was to take the array() creation one level up before the connections traversing.

      original code :
      public function importSchema($directory, array $connections = array(), array $options = array())
      {
      $classes = array();

      $manager = Doctrine_Manager::getInstance();
      foreach ($manager as $name => $connection) {
      // Limit the databases to the ones specified by $connections.
      // Check only happens if array is not empty
      if ( ! empty($connections) && ! in_array($name, $connections))

      { continue; }

      $builder = new Doctrine_Import_Builder();
      $builder->setTargetPath($directory);
      $builder->setOptions($options);

      $definitions = array(); // <<<<<<<<<<<<<<<<<<< STAYING THERE CAUSES THE "MISSING CLASSNAME" ERROR

      foreach ($connection->import->listTables() as $table) {
      ......

      modified code :

      public function importSchema($directory, array $connections = array(), array $options = array())
      {
      $classes = array();

      $manager = Doctrine_Manager::getInstance();
      $definitions = array(); // <<<<<<<<<<<<<<<<<<PUT HERE

      foreach ($manager as $name => $connection) {
      // Limit the databases to the ones specified by $connections.
      // Check only happens if array is not empty
      if ( ! empty($connections) && ! in_array($name, $connections)) { continue; }

      $builder = new Doctrine_Import_Builder();
      $builder->setTargetPath($directory);
      $builder->setOptions($options);

      foreach ($connection->import->listTables() as $table) {
      .......

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Jonathan H. Wage
            Reporter:
            Fabrice Agnello
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated: