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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T16:03:32+00:00 2026-05-30T16:03:32+00:00

In Symfony 2 book there is an example of how to do that for

  • 0

In Symfony 2 book there is an example of how to do that for ONE $product: http://symfony.com/doc/2.0/book/doctrine.html#fetching-related-objects

It is quite simple:

public function showAction($id)
{
$product = $this->getDoctrine()
    ->getRepository('AcmeStoreBundle:Product')
    ->find($id);

$categoryName = $product->getCategory()->getName();

// ...
}

But what if i want to fetch ALL products with category info joined automatically to each project?

Thank you!

  • 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-30T16:03:33+00:00Added an answer on May 30, 2026 at 4:03 pm

    This will do the trick:

    $products = $this->getDoctrine()->getRepository('AcmeStoreBundle:Product')->findAll();
    

    However, each time you do a getCategory on a product a sql query will be triggered which could result in performance issues.

    What you really want to do is to make yourself a ProductManager service and write an explicit query joining product and category. So only one sql query will be generated. The Doctrine 2 manual has plenty of examples.

    http://docs.doctrine-project.org/projects/doctrine-orm/en/2.1/reference/query-builder.html

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

Sidebar

Related Questions

I am following the book and on the page http://symfony.com/doc/current/book/doctrine.html While following the book
I read this: http://symfony.com/doc/current/book/service_container.html It said: $mailer = $this->get('my_mailer'); As an added bonus, the
I'm trying to follow this documentation on Symfony : http://symfony.com/doc/current/book/forms.html ok so here is
I need to create a form class,I'm following the symfony book in http://symfony.com/doc/current/book/forms.html I
hey i am working on form using the tutorial http://symfony.com/doc/current/book/forms.html I have created a
so im reading the internals documentation for symfony2 http://symfony.com/doc/current/book/internals.html and i dont understand this
As Symfony Book suggests ( http://symfony.com/doc/current/book/routing.html#required-and-optional-placeholders ), in order to create an optionar placeholder
When following Symfony2's validation documentation (http://symfony.com/doc/current/book/validation.html) the writer often refers to src/Acme/BlogBundle/Resources/config/validation.yml I also
I'm following the security chapter of the Symfony 2 book. There's is an example
in symfony 2.0 and django there are bundles that contain everything for a feature

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.