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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:53:35+00:00 2026-06-08T16:53:35+00:00

Im using Doctrine 2 ORM in my Zend project and need to serialize my

  • 0

Im using Doctrine 2 ORM in my Zend project and need to serialize my Entities to JSON in several cases.

ATM i use the Querybuilder and join all tables i need. But my serializer causes doctrine to lazy load every associated Entity which results in pretty huge data amounts and provokes recursion.

Now im looking for a way to totally disable Doctrines lazy loading behavior.

My way to select data would be the following:

$qb= $this->_em->createQueryBuilder()
            ->from("\Project\Entity\Personappointment", 'pa')
            ->select('pa', 't', 'c', 'a', 'aps', 'apt', 'p')
            ->leftjoin('pa.table', 't')
            ->leftjoin('pa.company', 'c')
            ->leftjoin('pa.appointment', 'a')
            ->leftjoin('a.appointmentstatus', 'aps')
            ->leftjoin('a.appointmenttype', 'apt')
            ->leftjoin('a.person','p')

I would like my resultset to only contain the selected tables and associations.

Any help would be greatly appreciated.

  • 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-08T16:53:39+00:00Added an answer on June 8, 2026 at 4:53 pm

    After having looked for the answer in Doctrine, my team figured out that the JMS Serializer was the “problem”.
    It triggered the use of Doctrine Proxies automatically. We wrote a Patch for JMS Serializer to avoid the Lazy Loading.

    We implemented our own DoctrineProxyHandler which just doesn’t trigger Doctrines lazyloading mechanism and registered it within our SerializationHandlers Array.

    class DoctrineProxyHandler implements SerializationHandlerInterface {
    
    public function serialize(VisitorInterface $visitor, $data, $type, &$handled)
    {
        if (($data instanceof Proxy || $data instanceof ORMProxy) && (!$data->__isInitialized__ || get_class($data) === $type)) {
            $handled = true;
    
            if (!$data->__isInitialized__) {
    
                //don't trigger doctrine lazy loading
                //$data->__load();
    
                return null;
            }
    
            $navigator = $visitor->getNavigator();
            $navigator->detachObject($data);
    
            // pass the parent class not to load the metadata for the proxy class
            return $navigator->accept($data, get_parent_class($data), $visitor);
        }
    
        return null;
    }
    

    Now i can simply select my table, join the associations i need – and my JSON will contain just the data i selected instead of infinite depth associations and recursions 🙂

    $qb= $this->_em->createQueryBuilder()
            ->from("\Project\Entity\Personappointment", 'pa')
            ->select('pa', 't', 'c', 'a')
            ->leftjoin('pa.table', 't')
            ->leftjoin('pa.company', 'c')
            ->leftjoin('pa.appointment', 'a')
    

    JSON will just contain

    {  
      Personappointment: { table {fields}, company {fields}, appointment {fields}}
      Personappointment: { table {fields}, company {fields}, appointment {fields}}
      Personappointment: { table {fields}, company {fields}, appointment {fields}}
      .
      .
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a Zend Framework project, using Doctrine as ORM. I ran into
I'm using Doctrine 1.2 as my ORM for a Zend Framework Project. I have
I've been working with Zend Framework (using Doctrine as the ORM) for quite a
I am using Doctrine ORM for php and Zend MVC. I have a mysql
I'm using Doctrine as ORM in my project but ran against a strange error:
I'm using Doctrine 2 ORM and I have this problem. I have three Entities,
I'm interested in using Doctrine as an ORM for a new Zend Framework app
I'm using Doctrine ORM in a project that I am working on. Although the
I'm using Zend Framework and I feel that I need a good ORM to
I've just uploaded my Zend project to my CentOS server. I am using Doctrine

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.