Doctrine2忽略数据库表 [英] Doctrine2 Ignore table of database

查看:148
本文介绍了Doctrine2忽略数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是Doctrine 2,我想生成一个我的数据库的ORM,但是我不想选择数据库的所有表。

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

例如,在此db中:


  • 表1没有主键

  • 表2是正常的

我只想选择这个命令的表2: / p>

I want to choose ONLY Table 2 with this command :

doctrine:mapping:convert --from-database yml ./src/Application/TestBundle/Resources/config/doctrine/metadata/orm --filter="Table2"

我有一个错误:


表Table_1没有主键。 Doctrine不支持从没有主键的表中进行逆向工程。

Table Table_1 has no primary key. Doctrine does not support reverse engineering from tables that don't have a primary key.

Ok我知道,但我不想我的表1在我的ORM。

Ok I know , but I don't want my table 1 in my ORM.

当我的表1具有主键时,我可以过滤表...

When my table 1 has primary key i can filter the tables...

我如何解决这个问题问题?

How can I resolve this problem ?

我看到这样:
使用symfony2和doctrine从现有数据库生成单个实体

但是它不

我回答我的问题。

在你的配置: config.yml ,添加 schema_filter ,在我的情况下:

In your configuration : config.yml , add schema_filter , in my case :

schema_filter: ~^(?!Table1)~


推荐答案

如果您使用Doctrine2没有Symfony,那么您应该将此行添加到您的引导中:

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)~");

整个引导看起来像

<?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__)~");

这篇关于Doctrine2忽略数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆