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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T00:24:03+00:00 2026-06-09T00:24:03+00:00

I have two entities that represent users ( User ) and friendship requests (

  • 0

I have two entities that represent users (User) and friendship requests (FriendshipRequest). There is a oneToMany relationship between User and FriendshipRequest, so Doctrine creates a method that is called getFriendshipRequests() in the class User. This is ok, but FriendshipRequest has an attribute that is called status, so I would like that the User class could filter the friendship requests associated to it attending to their status. I have read Doctrine documentation, and I found out this:

Natively you can’t filter associations in 2.0 and 2.1. You should use
DQL queries to query for the filtered set of entities.

According to this, I suppose that I should create a FriendshipRequest repository and create a method called “findByStatusAndUser” (or something like that), but I think that’s a crappy solution.

I would like to have a method in the User entity, like getPendingStatusRequests(). Is this possible? If it isn’t, what would be the best solution?

  • 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-09T00:24:06+00:00Added an answer on June 9, 2026 at 12:24 am

    I think that “getPendingRequestsForUser($user)” method in the FriendshipRequest repository should be a good solution. Inside this method you just need to create an appropriate DQL.

    This is a good solution, because all of the logic should be moved to repositories, leaving entities as small and clean as possible.

    UPD: Also, you could use findBy method, as described here, ex:

    $pendingRequests = $em->getRepository('MyBundle:FriendshipRequest')->findBy(
        array('user' => $user->getId(), 'status' => 1)
    );
    

    But for me, first method is preferred.

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

Sidebar

Related Questions

I have two classes that represent two different database entities. Their relationship is 1:m
I have two Doctrine entities that have a one-to-many relationship, like this: License class
Consider the following scenario We have a simple database that involves two entities: user
In my Rails app I have a fairly standard has_many relationship between two entities.
Consider that i have two entities with following relationship: Entity A <-->> Entity B
I have two entities that have a many-to-many relationship; they are mapped with annotations
I have two linqTOsql entities that has a parent and child relationship, one to
Say I have two entities in Doctrine2 that are related to each other, Models\User
I have two entities Foo and Bar with a Many to Many relationship between
I have two entities that have a relationship for which I create a join

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.