Doctrine2 - 单表继承

发布于 2024-12-13 02:32:02 字数 1162 浏览 0 评论 0原文

我正在尝试应用此

我有 2 个文件。第一个是 ProjectSetting.php

namespace Rueckgrat\App\Models;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity()
 * @ORM\Table(name="project_setting")
 * @ORM\HasLifecycleCallbacks()
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="is_production", type="integer")
 * @ORM\DiscriminatorMap({"0" = "ProjectCalculation", "1" = "ProjectSetting"})
 */
class ProjectSetting
{
// More code here
}

第二个是 ProjectCalculation.php

namespace Rueckgrat\App\Models;
use Doctrine\ORM\Mapping AS ORM;
/**
 * @ORM\Entity
 */
class ProjectCalculation extends \Rueckgrat\App\Models\ProjectSetting
{      
....
}

任何帮助或提示表示赞赏。

更新:

完整错误消息: 致命错误:无法在第 17 行 /Applications/MAMP/htdocs/Rueckgrat/app/models/ProjectSetting.php 中重新声明类 Rueckgrat\App\Models\ProjectSetting

我刚刚尝试了 Doctrine 文档中的示例,只是分成两个实体文件,它不工作。然后我将 ProjectCalculation 类复制到 ProjectSetting 文件中,它正在工作。

更新 2:

我无法更新我的架构,但当我保存 ProjectCalculation 实体时,它会将正确的鉴别器保存到 project_setting 表中。

I'm trying to apply this tutorial to my project, but I don't get it working. Everytime I try to update my schema i get an error:
Fatal error: Cannot redeclare class Rueckgrat\App\Models\ProjectSetting in.....

I have 2 files. The first one is ProjectSetting.php

namespace Rueckgrat\App\Models;

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity()
 * @ORM\Table(name="project_setting")
 * @ORM\HasLifecycleCallbacks()
 * @ORM\InheritanceType("SINGLE_TABLE")
 * @ORM\DiscriminatorColumn(name="is_production", type="integer")
 * @ORM\DiscriminatorMap({"0" = "ProjectCalculation", "1" = "ProjectSetting"})
 */
class ProjectSetting
{
// More code here
}

The second one is ProjectCalculation.php

namespace Rueckgrat\App\Models;
use Doctrine\ORM\Mapping AS ORM;
/**
 * @ORM\Entity
 */
class ProjectCalculation extends \Rueckgrat\App\Models\ProjectSetting
{      
....
}

Any help or hint appreciated.

Update:

Full error message:
Fatal error: Cannot redeclare class Rueckgrat\App\Models\ProjectSetting in /Applications/MAMP/htdocs/Rueckgrat/app/models/ProjectSetting.php on line 17

I just tried the example from the Doctrine documentation, just splited in two entity files and it is not working. Then i copied the ProjectCalculation class in the file of ProjectSetting and it is working.

Update 2:

I can't update my Schema, but it is saving the correct discriminator to the project_setting table, when i save an ProjectCalculation Entity.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉墨 2024-12-20 02:32:02

这可能是您计算机上的 PHP 加速器的问题。请关闭 APC 或 XCache(无论您有什么),重新启动 PHP/Apache,然后重试。

This can be the problem with PHP accelerator on your machine. Please turn off APC or XCache (whatever you have there), restart PHP/Apache and try again.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文