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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:14:03+00:00 2026-05-24T17:14:03+00:00

How do I perform queries in an entity? namespace Entities\Members; /** * @Entity(repositoryClass=\Entities\Member\MembersRepository) *

  • 0

How do I perform queries in an entity?

namespace Entities\Members;

/**
 * @Entity(repositoryClass="\Entities\Member\MembersRepository")
 * @Table(name="Members")
 * @HasLifecycleCallbacks
 */
class Members extends \Entities\AbstractEntity
{
    /**
     * @Id @Column(name="id", type="bigint",length=15)
     * @GeneratedValue(strategy="AUTO")
     */
    protected $id;

    /** 
     * @Column(name="userid", type="bigint", length=26, nullable=true) 
     */
    protected $userid;

    /** 
     * @Column(name="fname", type="string", length=255,nullable=true) 
     */
    protected $fname;

    /**
     *  @OneToMany(targetEntity="\Entities\Users\Wall", mappedBy="entry", cascade={"persist"}) 
     */
    protected $commententries;

    public function __construct()
    {
        $this->commententries = new \Doctrine\Common\Collections\ArrayCollection();
    }
}

Example I would like to have a function inside this entity called: filter()
and I want to be able to filter the commententries collection. It should return a collection with a certain condition such id=1. Basically it should be filtering the data received from the join query.

So something like this:

$this->commententries->findBy(array('id' => 1));

But obviously this does not work.

  • 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-24T17:14:04+00:00Added an answer on May 24, 2026 at 5:14 pm

    Generally speaking, you shouldn’t do this.

    Entities, as a rule of thumb, should not know about the entitymanager (directly, or via some intermediary object).

    The reason for this is mostly testability, but in my experience, it helps keeps things organized in other ways.

    I’d approach it by designing a service class that handles the lookups for you. Your controller (or whatever) would drive it like this:

    <?php
    // create a new service, injecting the entitymanager.  if you later wanted 
    // to start caching some things, you might inject a cache driver as well.
    $member = $em->find('Member',$member_id); //get a member, some how.
    $svc = new MemberService($em);
    
    $favoriteCommentaries = $svc->getFavoriteCommentaries($member);
    

    As I hint in the comment, if you decide later that you want to add caching (via memcached, for instance) to avoid frequent lookups, you’d do that somewhere near or in this service class. This keeps your entities nice and simple, and easily testable. Since you inject your entitymanager into the service at construction-time, you can mock that as needed.

    getFavoriteCommentaries() could use various implementations. A trivial one would be to proxy it to Member::getFavoriteCommentaries(), which would actually load everything, and then filter out the “favorite” ones. That probably won’t scale particularly well, so you could improve it by using the EM to fetch just the data you need.

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

Sidebar

Related Questions

Consider these 3 table structures. Which will perform these queries the best. Structure 1
These are my sample classes on what I what to perform queries. class TObject
What's the general consensus on using LINQ to perform queries and manipulation inline and
I thought that compiled queries would perform the same query translation as DataContext. Yet
I have several Oracle queries that perform well when run through SQL*PLUS. However when
Is there any way to perform SQL Like Queries or Filtering on Java Data
I am using the Xerces implementation within JDK6 to perform XPath queries on an
I need to perform queries in a ADO.NET model by using LINQ. I have
If they only perform queries on it? Something like: private SQLiteDatabase db; @Override public
I'm working on a project where we are using fluent nhibernate and perform queries

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.