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

  • Home
  • SEARCH
  • 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 8204975
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T08:04:03+00:00 2026-06-07T08:04:03+00:00

I have these two entities: Message entity class Message { /** * @ManyToOne(targetEntity=User) *

  • 0

I have these two entities:

Message entity

class Message
{
    /**
    * @ManyToOne(targetEntity="User")
    * @JoinColumn(name="author", referencedColumnName="id_user")
    */
    protected $author;

User entity

class User
{
    /**
     * @Id
     * @Column(type="integer", nullable=false, name="id_user")
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /**
     * @Column(type="string", nullable=false)
     */
    protected $name;

I need to get the total of messages of user and its data in order to echo something like this:

echo $user->getName() . " have {$user->totalOfMessage()}";

I now that I can make a relation in User entity to get a message collection. But I don’t know if it necessary only to get the size.

  • 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-07T08:04:04+00:00Added an answer on June 7, 2026 at 8:04 am

    Well, I found the answer. At least one good option.

    As of Doctrine 2.1 you can mark associations as extra lazy. This means that calling $user->getMessages()->count() won’t load the messages, it will just issue a COUNT query to the database.

    You can read about extra lazy collections here: https://www.doctrine-project.org/projects/doctrine-orm/en/2.7/tutorials/extra-lazy-associations.html

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

Sidebar

Related Questions

I have these two entities. One for Employees: [Table(Name = Employees)] public class Employee
Let's say I have these two very basic entities: public class ParentEntity { public
consider these two entities: /** @Entity */ class String { /** @Id @Column(type=integer) *
I have two entities, User and UserSetting. The obvious relationship between these two has
I have these two tables people ============ id, name and answer_sheets ============ id, person_id,
I have these two modules : package G1; sub new { my $class =
I have these two classes public class Person { } public class Company {
I have these two methods on a class that differ only in one method
I have problems creating a custom query. This is what entities: @Entity public class
I have two entities, projects and users. These are modeled in Rails using Mongoid

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.