0
我有點困惑於Doctrine的文檔,所以也許你可以幫助我。我有以下類繼承:Doctrine2類表繼承
<?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
{
....
}
我不知道我做錯了。你可以幫我嗎?
?>