I am a little bit confused by Doctrine's documentation so maybe you can help me. I have the following class inheritance:
<?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;
}
?>
I want to store each class in a separate table. The role defines the type of user by an id. How would I solve this problem? I tried this:
<?php
/**
* @Entity
* @Table(name="user")
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="role_id", type="integer")
* @DiscriminatorMap({"1" = "User", "2" = "Customer"})
*/
class User
{
...
}
?>
I am not sure how to handle the role class in this scenario.
Thank you for your answer. Now I tried this and got following error:
[Doctrine\DBAL\Schema\SchemaException]
There is no column with name '_id' on table 'customer'.
I have following code:
<?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
{
....
}
I do not know what I am doing wrong. Can you help me?
?>