I would like to use Class Table Inheritance
:
/**
* @Entity
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discr", type="string")
* @DiscriminatorMap({"player" = "Player", "admin" = "Admin"})
*/
class User
{
// ...
}
/** @Entity */
class Player extends User
{
// ...
}
/** @Entity */
class Admin extends User
{
// ...
}
My question is:
If I have a Collection of User
s, how is it possible to check, which one is an Admin
and which one is a Player
. And how to call a method of the subclass after that?
How do you manage to get a collection of Users
?
Doctrine instantiates concrete classes of Player
and Admin
depending on value of DiscriminatorColumn
. You can check which entity you get with instanceof
:
switch(true){
$entity instanceof Player:
// do player's stuff
break;
$entity instanceof Admin:
// do admin's stuff
break;
}