How to set up entity (doctrine) for database view in Symfony 2

前端 未结 6 1374
心在旅途
心在旅途 2020-11-30 01:51

Lets say i have a view table. And i want to get data from it to an entity. Can i (and how) create entity class to do that. (no save operation needed). I just want to display

6条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-30 02:33

    In addition to above answer, I have mixed some of your example code to extend the DoctrineUpdateCommand

    This is my DoctrineUpdateCommand:

    class DoctrineUpdateCommand extends UpdateSchemaDoctrineCommand{
       protected function executeSchemaCommand(InputInterface $input, OutputInterface $output, SchemaTool $schemaTool, array $metadatas) {
          $container = $this->getApplication()->getKernel()->getContainer();  
    
         $filterExpr = $container->get('doctrine')->getEntityManager()->getConnection()->getConfiguration()->getFilterSchemaAssetsExpression();
         $emptyFilterExpression = empty($filterExpr);
    
         /** @var $newMetadatas \Doctrine\ORM\Mapping\ClassMetadata */
         $newMetadatas = array();
    
         foreach ($metadatas as $metadata) {
            if(($emptyFilterExpression||preg_match($filterExpr, $metadata->getTableName()))){
                array_push($newMetadatas, $metadata);
            }        
         }
    
         parent::executeSchemaCommand($input, $output, $schemaTool, $newMetadatas);
     }
    }
    

    Thanks for the right way

提交回复
热议问题