【发布时间】:2025-12-10 08:05:01
【问题描述】:
我在 symfony2 中扩展具有相同数据库表名的实体时遇到问题。 我正在尝试在 symfony 中扩展一个实体,但基础实体需要可重用,所以它不会总是被扩展。
这是我目前拥有的简化示例。 我的客户实体:
namespace Bundle\Entity\Customer;
/**
* @ORM\Table(name="customer")
* @ORM\Entity()
*/
class Customer implements CustomerInterface, UserInterface
{
//implementing variables and getters/setters
}
扩展实体(在另一个包中):
namespace AnotherBundle\Entity\Customer;
use Bundle\Entity\Customer\Customer as BaseCustomer;
/**
* @ORM\Entity()
*/
class Customer extends BaseCustomer
{
//implementing variables and getters/setters
}
客户界面:
namespace Bundle\Model\Customer;
interface CustomerInterface
{
// public methods of the first Customer class
}
在我的 config.yml 我有以下规则:
resolve_target_entities:
Bundle\Model\Customer\CustomerInterface: AnotherBundle\Entity\Customer\Customer
生成 SQL 时出现以下错误:
[Doctrine\DBAL\Schema\SchemaException]
The table with name 'customer' already exists.
我需要第二个实体来扩展第一个(基本)实体并维护数据库表名。但是当我不扩展第一个(基础)实体时,我仍然希望这个实体能够独立工作。
我已经尝试过这个来源,但他们无法解决我的问题: Creating portable Bundles with extendable entities in Symfony2(没用,虽然实体确实映射到了正确的,但它仍然给了我重复的表名错误)
此外,学说的继承映射似乎没有帮助 (http://docs.doctrine-project.org/en/latest/reference/inheritance-mapping.html)
我理解错误,但是否应该能够让 2 个实体(相互扩展)写入同一个数据库表
【问题讨论】:
标签: symfony doctrine-orm