Symfony 3.3 Doctrine Fixtures 加载跳过 SQL 视图

Symfony 3.3 Doctrine Fixtures Load skipping SQL views

我正在尝试将 SQL 视图与 Doctrine 一起使用。

到目前为止一切正常,但是当 运行 加载基本装置(没有选项)时我遇到了问题。我收到以下错误消息。

[Doctrine\DBAL\DBALException]
An exception occurred while executing 'DELETE FROM gp_items':

SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.


[Doctrine\DBAL\Driver\PDOException]
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.


[PDOException]
SQLSTATE[42000]: [Microsoft][ODBC Driver 13 for SQL Server][SQL Server]View or function 'gp_items' is not updatable
because the modification affects multiple base tables.

我查看了从捆绑包中加载固定装置的代码 ("doctrine/doctrine-fixtures-bundle": "^2.3"),我认为我必须对 ORMPurger (Doctrine\Common\DataFixtures\Purger) 进行一些更改,但我'我不知道该怎么做。

所以我想知道如何覆盖特定 class 中的函数。

干杯!

我遇到了类似的问题。我很懒,所以我做了解决方法以这种方式加载我们的固定装置。
我找到了一个干净的解决方案,我很感兴趣

bin/console -e=test doctrine:database:drop --if-exists --force
bin/console -e=test doctrine:database:create --if-not-exists --no-interaction
bin/console -e=test doctrine:migrations:migrate --no-interaction
bin/console -e=test doctrine:fixtures:load --append --no-interaction

好的,

所以我决定 fork DoctrineFixturesBundle 并在我的项目中使用我自己的版本。

https://github.com/jbonnier/DoctrineFixturesBundle

为了让 composer 使用它,我修改了我的 composer.json 文件,在最后一个右括号之前添加了以下代码。

,
    "repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/jbonnier/DoctrineFixturesBundle"
        }
    ] 

我还更改了我的 require-dev 语句以使用我的个人分支。

 "require-dev": {
    "doctrine/doctrine-fixtures-bundle": "dev-jbonnier",
   ...
}

编辑:

补充说明。

目前使用捆绑包的 v2.4.1 版本。

这是我对其所做的更改。

文件:Command/LoadDataFixturesDoctrineCommand.php

更改了第 113 行

来自

$purger = new ORMPurger($em);

$purger = new ORMPurger($em, $this->listViews($input->getOption('em')));

在第 136 行后 class 添加函数

/**
 * Return an array with all views names in the database. 
 *
 * @return array
 */
protected function listViews($entityManager)
{
    $em = $this->getContainer()->get('doctrine')->getManager($entityManager);
    $conn = $em->getConnection();
    $sm = $conn->getSchemaManager();

    $views = $sm->listViews();
    $rst = array();

    foreach ($views as $view)
    {
        array_push($rst, $view->getName());
    }

    return $rst;
}