I have base entity Article

Code: Select all
    /**
    * Vido\CoreBundle\Entity\Article
    *
    * @ORM\Table(name="articles")
    * @ORM\HasLifecycleCallbacks()
    * @ORM\Entity(repositoryClass="Vido\CoreBundle\Repository
\ArticleRepository")
    * @ORM\InheritanceType("JOINED")
    * @ORM\DiscriminatorColumn(name="type", type="string")
    * @ORM\DiscriminatorMap({ "Video" = "Video", "News" = "News",
"Media" = "Media"})
    */
    class Article
    {
        /**
         * @var integer $id
         *
         * @ORM\Column(name="id", type="integer", nullable=false)
         * @ORM\Id
         * @ORM\GeneratedValue(strategy="IDENTITY")
         */
        protected $id;

        /**
         * @var integer $createdAt
         *
         * @ORM\Column(name="created_at", type="integer",
nullable=false)
         */
        protected $createdAt = 0;
    .....


and a couple entities extending it - Video, News, Media etc.
something like

Code: Select all
    /**
    * Vido\CoreBundle\Entity\Video
    * @ORM\Table()
    * @ORM\Entity(repositoryClass="Vido\CoreBundle\Repository
\VideoRepository")
    * @ORM\HasLifecycleCallbacks()
    */
    class Video extends Article
    {
        /**
         * @var string $videoSourceFile
         *
         * @ORM\Column(name="video_source_file", type="string",
length=255, nullable=true)
         */
        protected $videoSourceFile = '';

        /**
         * @var boolean $isVideoConverted
         *
         * @ORM\Column(name="is_video_converted", type="boolean",
nullable=false)
         */
        protected $isVideoConverted = false;



Everything works great :), except 3 problems.

1) As I see in my table "articles" there is field "type", which have
values like "Video", "News" etc. But when I got collection of the
child items - they dont have field type, so I have added ugly code
like

Code: Select all
    public function getType()
        {
            return "Video";
        }

to all child entities. :( How it can be done in "right" way?

2) I am not sure, how I can get collection of the items with different
types? (Like get all news/videos/medias sorted by date and show them
by using different templates in twig) - I have only ugly solution -
get collection of the articles and for each item generate child object
based on ID in cycle - kind of ugly :(

3) whenever I run entity generation command, like php app\console
doctrine:generate:entities VidoCoreBundle:Video - it generate in child
class (Video) ALL properties of the parent class and all get/set
functions.. Class become very overloaded with code - one of the
benefits from doctrine2 inheritance is lost :(
Can it be solved in some way? Maybe I misconfigured something etc.?

-- 
If you want to report a vulnerability issue on symfony, please send it to 
security at symfony-project.com

You received this message because you are subscribed to the Google
Groups "symfony developers" group.
To post to this group, send email to symfony-devs@googlegroups.com
To unsubscribe from this group, send email to
symfony-devs+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/symfony-devs?hl=en

Reply via email to