使用单表继承时,Doctrine无法生成模式吗? [英] Doctrine can't generate a schema when using single table inheritance?
问题描述
一个有趣的问题.我正在使用Symfony 2构建应用程序,并且试图让Doctrine从我的实体类中自动生成我的架构.我有两个实体类,分别是 Invoice
和 CreditNote
. CreditNote
扩展了 Invoice
.他们看起来像这样-
Invoice.php-
命名空间My \ Bundle \ BillingBundle \ Entity;使用Doctrine \ ORM \ Mapping作为ORM;/*** @ORM \实体* @ORM \ Table(name =发票")* @ORM \ InheritanceType("SINGLE_TABLE")* @ORM \ DiscriminatorColumn(name ="discriminator",type ="string")* @ORM \ DiscriminatorMap({"invoice" ="Invoice","credit_note" ="CreditNote"})*/类发票{...}
和CreditNote.php-
命名空间My \ Bundle \ BillingBundle \ Entity;使用Doctrine \ ORM \ Mapping作为ORM;/*** @ORM \实体*/CreditNote类扩展发票{...}
...所有这些似乎都遵循了Doctrine关于单表继承的指导,位于解决方案
它是100%正常工作的代码-我刚刚尝试过
您可能只需要使用以下方法清理缓存:
php应用程序/控制台缓存:清除&&php应用程序/控制台缓存:clear --env = prod
但是我使用php app/console doctrine:schema:update(不是doctrine:database:create)
An interesting problem. I'm building an application using Symfony 2 and I'm trying to get Doctrine to auto-generate my schema from my entity classes. I have two entity classes, Invoice
and CreditNote
. CreditNote
extends Invoice
. They look like this -
Invoice.php -
namespace My\Bundle\BillingBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
* @ORM\Table(name="invoice")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="discriminator", type="string")
* @ORM\DiscriminatorMap({"invoice" = "Invoice", "credit_note" = "CreditNote"})
*/
class Invoice
{ ... }
and CreditNote.php -
namespace My\Bundle\BillingBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* @ORM\Entity
*/
class CreditNote extends Invoice
{ ... }
...all of which seems to follow Doctrine's guidance on single table inheritance at http://docs.doctrine-project.org/en/2.0.x/reference/inheritance-mapping.html#single-table-inheritance.
But, when I try to run php app/console doctrine:database:create
in order to generate my schema I get the error -
PHP Fatal error: Cannot redeclare class My\Bundle\BillingBundle\Entity\Invoice in <my-app>/src/My/Bundle/BillingBundle/Entity/Invoice.php on line 15
Which suggests that the Invoice
class has already been declared (but it honestly hasn't). More interesting is that if I rename the Invoice
class to AInvoice
(i.e. something that comes before CreditNote
in the alphabet, then everything works.
So, it seems like the generator is loading up CreditNote.php
, finding a class that extends Invoice
and then loading Invoice.php
, then finding the Invoice.php
file again and trying to parse it a second time. Only that seems the kind of thing that someone would have fixed by now.
Any thoughts? Thanks.
it is 100% working code - I tried just
You may need just to clean the cache using:
php app/console cache:clear && php app/console cache:clear --env=prod
but I use php app/console doctrine:schema:update (not doctrine:database:create)
这篇关于使用单表继承时,Doctrine无法生成模式吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!