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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T14:32:23+00:00 2026-06-13T14:32:23+00:00

I have Album, Content, File and Comment entities where Comment and File is a

  • 0

I have Album, Content, File and Comment entities where Comment and File is a relation of Content, and Content is related to Album.

I want to retrieve all relations (File and Comment entities) from a single Content entity (and not load them for any of the other contents). There should be no more than 2 queries to the database.

What’s a good way of retrieving the relations using a single query, and populate the entity object?

E.G

$album = $em->createQuery('SELECT a,c FROM Album JOIN a.contents c WHERE a.id = :id')->getOneOrNullResult();

foreach ($album->getContents() as $content) {
    if ($content->getId() == $id) {
         // Load all (relevant) relations for this content in a single query with joins
         $em->MAGIC($content);
    }
}
  • 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-13T14:32:25+00:00Added an answer on June 13, 2026 at 2:32 pm

    I found a solution to this. By defining Content, such that it can only be a member of a single album at the time – I can join album by Content as such:

    $dql = 'SELECT a,c,cc,cf,ac FROM Content c JOIN c.album a JOIN a.content ac JOIN c.comments cc JOIN c.file cf WHERE c.id = :id'
    

    Then Doctrine 2 magic make sure that the returned content, is referencing the same object in the $album->contents property as well.

    End result, is a single query.

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

Sidebar

Related Questions

I have an issue with importing a picture from the Album in Android, because
Suppose I have the following list: ID3_tag = ['Title','Artist','Album','Track'] And I have a file
I want to get all photo fids albums. For example, I have albums and
I have an mp3 file on a server. I want to get this file's
I want to have the content of my website centred but only for a
I have saved photos to my customised album in my app using code [library
I have a image folder which contains sub directory for each album of images
I have a ms access database that has one table for each photo album
I have a search engine that searches albums. For each music album, I have
I have this json content inside a var in php: { data: [ {

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.