Doctrine2 Ignore table of database

前端 未结 3 1305
谎友^
谎友^ 2021-02-07 19:54

I\'m using Doctrine 2 and I want to generate an ORM of my database but I don\'t want select all tables of the db.

For example, in this db :

  • Table 1 has
相关标签:
3条回答
  • 2021-02-07 20:21

    Doctrine first validates your tables and only then executes the command. So you should always have valid DB schema in order to make any operations with it.

    0 讨论(0)
  • 2021-02-07 20:29

    Ignoring the table was the solution:

    doctrine:
        dbal:
            schema_filter: ~^(?!Table1)~
    
    0 讨论(0)
  • 2021-02-07 20:38

    If you use Doctrine2 without Symfony then you should add this line to your bootstrap:

    // With this expression all tables prefixed with Table1 will ignored by the schema tool.
    $entityManager->getConnection()->getConfiguration()->setFilterSchemaAssetsExpression("~^(?!Table1)~");
    

    the whole bootstrap looks like

    <?php
    // bootstrap.php
    
    use Doctrine\ORM\Tools\Setup;
    use Doctrine\ORM\EntityManager;
    
    
    // Include Composer Autoload (relative to project root).
    require_once "vendor/autoload.php";
    
    // Create a simple "default" Doctrine ORM configuration for Annotations
    $isDevMode = true;
    $paths = array(__DIR__."/doctrine/entities");
    
    $config = Setup::createAnnotationMetadataConfiguration($paths, $isDevMode);
    //$config = Setup::createYAMLMetadataConfiguration(array(__DIR__."/doctrine/yaml"), $isDevMode);
    
    // the connection configuration
    $dbParams = array(
      'driver'   => 'pdo_mysql',
      'user'     => 'username',
      'password' => 'password',
      'dbname'   => 'database',
    );
    
    /** @var $entityManager \Doctrine\ORM\EntityManager */
    $entityManager = EntityManager::create($dbParams, $config);
    
    
    // Set the other connections parameters
    $conn = $entityManager->getConnection();
    
    
    $platform = $conn->getDatabasePlatform();
    $platform->registerDoctrineTypeMapping('enum', 'string');
    
    
    // With this expression all tables prefixed with t_ will ignored by the schema tool.
    $conn->getConfiguration()->setFilterSchemaAssetsExpression("~^(?!t__)~");
    
    0 讨论(0)
提交回复
热议问题