我对 Doctrine 的文档有点困惑,所以也许你可以帮助我。我有以下类继承:
<?php
class User
{
/**
* @var int
*/
private $_id;
/**
* @var Role
*/
private $_role;
}
class Company extends User
{
}
class Customer extends User
{
...
}
class Role
{
/**
* @var int
*/
private $_id;
}
?>
我想将每个类存储在一个单独的表中。角色通过 id 定义用户的类型。我将如何解决这个问题?我试过这个:
<?php
/**
* @Entity
* @Table(name="user")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="role_id", type="integer")
* @DiscriminatorMap({"1" = "User", "2" = "Customer"})
*/
class User
{
...
}
?>
我不确定在这种情况下如何处理角色类。
谢谢您的回答。现在我尝试了这个并得到以下错误:
[Doctrine\DBAL\Schema\SchemaException]
There is no column with name '_id' on table 'customer'.
我有以下代码:
<?php
/**
* Class Sb_User
*
* @Entity
* @Table(name="user")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="role_id", type="integer")
* @DiscriminatorMap({"2" = "Sb_Customer", "8" = "Sb_Pos"})
*/
class Sb_User implements Sb_User_Interface
{
/**
* @Id
* @GeneratedValue
* @Column(name="id", type="integer")
* @var int
*/
protected $_id;
...
}
/**
* Class Sb_Customer
*
* @Entity
* @EntityResult(discriminatorColumn="role_id")
* @Table(name="customer")
*
*/
class Sb_Customer extends Sb_User implements Sb_Customer_Interface
{
....
}
我不知道我做错了什么。你能帮助我吗?
?>