symfony - Comment entity related to Article or Product -


i have entities "article" , "product". want add comments these 2 entities. should create 2 different entities "articlecomment" , "productcomment" same properties, , build manytoone relation respective entity, or create single "comment" entity , find way build relation both "article" , "product" entities. considering solution #2, how ?

considering solution #2, how ?

one way use single table inheritance

single table inheritance inheritance mapping strategy classes of hierarchy mapped single database table. in order distinguish row represents type in hierarchy so-called discriminator column used.

this means can create 2 separate entities articlecomment , productcomment both extending comment. use advantages discriminatormap column provides.

your comment entity hold relation called parent instance refer either article or product entities. creating new instance of articlecomment or productcomment discriminator map field automatically populated depending on type you're using.

this give advantages using dql query related comments type. example documentation:

$query = $em->createquery('select u doctrine\tests\models\company\companyperson u u instance of doctrine\tests\models\company\companyemployee'); 

and more. can read chapter here. of course sample , can use different approach.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -

How to provide Authorization & Authentication using Asp.net, C#? -