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 7010749
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:02:14+00:00 2026-05-27T22:02:14+00:00

I have an Article and Comment entity (oneToMany) On Comment prepersist lifecycle event I

  • 0

I have an Article and Comment entity (oneToMany)

On Comment prepersist lifecycle event I would like to count how many comments there are for this article and update Article’s comment_count field.

If I understand symfony2 approach correctly, I need to write a service for this. Let’s call it CommentCountManager.

My question is: How exactly do I make container available in entity so that I can get the CommentCountManager and triger the funciton that count comment for given article, and how do I access Doctrine’s entity manager in my CommentCountManager so that I can actually run queries there?

Am I on the right path?

Your help is greatly appreciated.

  • 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-05-27T22:02:15+00:00Added an answer on May 27, 2026 at 10:02 pm

    You don’t need to store the comments count in a separate column — you can count them on output. What you are trying to do is denormalization and I recommend avoiding it unless you absolutely need it for performance reasons — and only when you are sure that that part is causing the problems. But even then, query optimization and caching are much better alternatives to denormalization.

    Making entities aware of the container is a bad idea too. If you need this, then you are doing something wrong.

    To access an entity manager in a service, you need to inject it.

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

Sidebar

Related Questions

assume I have two objects article and comment . What I would like to
I have the following problem: I have two models: Article and Comment, in Comments,
Let's say I'm building an Article / Comment system like this: class Article(models.Model): title
I have article model with public ICollection<Comment> Comments { get; set; } and comment
I have an Article and Comments entities which are related together in a one-to-many
So I have two tables, article and comments (which has one-to-many relationship (1 article
I have a really simple Rails app. Basically an article with comments. I want
I have followed this article and implemented my service and I can open the
I have read this article from High Scalability about Stack Overflow and other large
I have read this article about 400% boost of your website . This is

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.