Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8442029
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:44:04+00:00 2026-06-10T08:44:04+00:00

I have in my Symfony 2.1 RC app a simple Comment model (using Doctrine

  • 0

I have in my Symfony 2.1 RC app a simple Comment model (using Doctrine 2). Every comment has a user and a message.

Currently, the CommentBundle manages comments on articles. I’d like it to be more generic to be able to comment any kind of entity without copying code across different bundles dedicated to comments…

For this to work, I also need a way to reference any entity from the comment one. I think having two fields entity_type and entity_id can be a nice solution. However, I can’t get the object from these without mapping entity_type to classes manually and using the find method.

So how do I reference an entity from a comment ? And how can I create generic behavior working on several entities ?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:44:06+00:00Added an answer on June 10, 2026 at 8:44 am

    You can create a abstract base class entity called Commentable and create entities that inherit Commentable such as Document or Post.

    Since Document and Post are derived from Commentable, you can create a one to many relationship between the entities Commentable and Comment respectively.

    Make sure to include in your base class ORM annotations for inheritance:

    @InheritanceType
    @DiscriminatorColumn
    @DiscriminatorMap
    

    Examples can be found on Doctrine Project Inheritance Documentation

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Symfony 1.4 app using sfDoctrineGuardPlugin for users. I need to move
I have a developed a small web-app in Symfony 2 and Doctrine 2. Can
I am implementing a web app using symfony 2. It has a main page
I have an existing, non-framework-based PHP/MySQL website. It has a simple security model, with
In my Symfony/Doctrine app, I have a query that orders by RANDOM(). I call
I'm developing game app and using Symfony 2.0. I have many AJAX requests to
I have a symfony project with the followin structure SDCU |-app |-----cache |-----logs |-bin
I have a Symfony2 project with a MySQL db: #app/config/config.yml doctrine: dbal: driver: %database_driver%
I am using symfony 1.0 and have set routing for few URLs as below.
I have a Symfony app that populates the widgets of a portal application and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.