orm
orm copied to clipboard
Entity inheritance
My classes definition:
** @Entity */
class User
{
/** @Column(type="primary") */
public $id;
}
/** @Entity */
class CustomUser extends User
{
/** @Column(type="string") */
public $email;
}
DI container configuration
$container = new Container();
$container->setDefinitions([ User::class => CustomUser::class ]);
Finding entity with class defined in DI container
$definitions = $container->getDefinitions();
$definition = $definitions[User::class];
// $definition is equal ['class' => 'path\to\CustomUser']
$entity = $orm->getRepository($definition['class'])->findOne([...]);
Now I try to get class of $entity
get_class($entity);
I expecting to get CustomUser but got User
Hi,
I'm not quite sure what container you use. But both User and CustomUser will share the same repository (we might add a feature to use custom repositories in the future).
Since you store both objects in one table it is possible to receive User instead of CustomUser (unless adding __type condition).
https://cycle-orm.dev/docs/advanced-single-table-inheritance#querying