I do not get simple table inheritance to work on my blog.
Here is what I have:
3 simple classes
- General abstract comment class
- Subclass for comments made to blog posts with a foreign key, to one
- Subclass for comments about actions also with a foreign key
General comment structure
/**
* @ORM\MappedSuperClass
* @ORM\Entity(repositoryClass="MY\BlogBundle\Entity\Repository\CommentRepository")
* @ORM\Table(name="blog_comment")
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap( {"blogentry" = "BlogComment", "activity" = "ActivityComment"} )
* @ORM\HasLifecycleCallbacks
*/
abstract class Comment
{
/**
* @ORM\Column(name="id", type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/
private $id;
/**
* @ORM\Column(name="title", type="string", length=255, nullable=true)
* @Assert\NotBlank()
*/
private $title;
...
Blog commentary
class BlogComment extends Comment
{
private $blogEntry;
...
Commentary on the action
class ActivityComment extends Comment
{
private $activity;
...
Building all objects with
./app/console doctrine:generate:entities MY
works fine, this means that superclass methods, such as getId(), will be automatically inserted into the class Comment.
And the only functions inside the subclasses are setter and getter for their own properties, such as getBlogEntry()orgetActivity()
, :
./app/console doctrine:migrations:diff -vvv
[ReflectionException]
Property MY\BlogBundle\Entity\ActivityComment::$id does not exist
Exception trace:
() at MY_PATH/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php:79
ReflectionProperty->__construct() at MY_PATH/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php:79
Doctrine\Common\Persistence\Mapping\RuntimeReflectionService->getAccessibleProperty() at MY_PATH/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php:889
Doctrine\ORM\Mapping\ClassMetadataInfo->wakeupReflection() at MY_PATH/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataFactory.php:537
Doctrine\ORM\Mapping\ClassMetadataFactory->wakeupReflection() at MY_PATH/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:209
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getMetadataFor() at MY_PATH/vendor/doctrine/common/lib/Doctrine/Common/Persistence/Mapping/AbstractClassMetadataFactory.php:114
Doctrine\Common\Persistence\Mapping\AbstractClassMetadataFactory->getAllMetadata() at MY_PATH/vendor/doctrine/migrations/lib/Doctrine/DBAL/Migrations/Tools/Console/Command/DiffCommand.php:68
Doctrine\DBAL\Migrations\Tools\Console\Command\DiffCommand->execute() at MY_PATH/vendor/doctrine/doctrine-migrations-bundle/Doctrine/Bundle/MigrationsBundle/Command/MigrationsDiffDoctrineCommand.php:49
Doctrine\Bundle\MigrationsBundle\Command\MigrationsDiffDoctrineCommand->execute() at MY_PATH/vendor/symfony/console/Symfony/Component/Console/Command/Command.php:252
Symfony\Component\Console\Command\Command->run() at MY_PATH/vendor/symfony/console/Symfony/Component/Console/Application.php:900
Symfony\Component\Console\Application->doRunCommand() at MY_PATH/vendor/symfony/console/Symfony/Component/Console/Application.php:192
Symfony\Component\Console\Application->doRun() at MY_PATH/vendor/symfony/symfony/src/Symfony/Bundle/FrameworkBundle/Console/Application.php:96
Symfony\Bundle\FrameworkBundle\Console\Application->doRun() at MY_PATH/vendor/symfony/console/Symfony/Component/Console/Application.php:123
Symfony\Component\Console\Application->run() at MY_PATH/app/console:22
id .
. $id public protected, ./app/console doctrine:generate:entities MY
, , . :
- /
@ORM\Table(name="blog_comment")- .
- , . .