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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:39:12+00:00 2026-05-26T09:39:12+00:00

I’m having some trouble pulling up relationed objects from my database using Doctrine2 in

  • 0

I’m having some trouble pulling up relationed objects from my database using Doctrine2 in Symfony2. I have a custom repository with the following function:

public function getOrder($id) {
    $DQL = 'SELECT request, orderer
    FROM OrderRequestBundle:OrderRequest request
    JOIN request.orderer orderer
    WHERE request.id = :id';

    $query = $this->getEntityManager()->createQuery($DQL)
                ->setParameter('id', $id)
                ->setMaxResults(1);
    return $query->getResult();
}

…but for some reason when I run this function I get back a Proxy object for an OrderRequest object rather than a real instance of OrderRequest, am I missing something? It seems that Doctrine2 loves lazy-loading and I can’t seem to get it up off its ass and fetch objects for me.

UPDATE:
I’m attempting to simply display the information in a Twig template with the code below:

$order = $this->getDoctrine()
    ->getRepository('OrderRequestBundle:OrderRequest')
    ->getOrder($id);

return $this->render('OrderRequestBundle:Admin:view.html.twig', array('order' => $order));

Where Twig calls information about the ‘order’ variable as so:

{{ order.quantity }}

…but I just end up with this error:

Item "quantity" for "Array" does not exist in "OrderRequestBundle:Admin:view.html.twig" at line 5
  • 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-26T09:39:12+00:00Added an answer on May 26, 2026 at 9:39 am

    UPDATE

    Given your edit, the problem isn’t proxy objects at all, it’s how you’re using your $query object.

    $query->getResult() will return an array of results. In an instance like this where you’re limiting the result set to a max of 1 row, it’ll return an array with one entry, but still an array. Twig chokes on this when trying to use accessor methods, naturally.

    What you’ll want to do is use $query->getSingleResult() instead. Note that Doctrine will throw a non-unique result exception if the query returns more than one row, so you need to be sure to use it with setMaxResults(1) like you’re doing if the query can possibly return multiple results.

    END UPDATE

    From the documentation on reference proxies:

    Here $item is actually an instance of the proxy class that was
    generated for the Item class but your code does not need to care. In
    fact it should not care. Proxy objects should be transparent to your
    code.

    Emphasis theirs. Proxies should be transparent to your code, and exist to improve performance where possible; however, if you have a pressing need to eager-load part of the query, you can either set the fetch mode in your entity configuration file, or check out this section of the docs:

    $query = $em->createQuery("SELECT u FROM MyProject\User u");
    $query->setFetchMode("MyProject\User", "address", "EAGER");
    $query->execute();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
We're building an app, our first using Rails 3, and we're having to build
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have some data like this: 1 2 3 4 5 9 2 6
I have a text area in my form which accepts all possible characters from
I have a reasonable size flat file database of text documents mostly saved in
I'm having trouble keeping the paragraph square between the quote marks. In firefox the
I have thousands of HTML files to process using Groovy/Java and I need to

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.