Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proxies with Doctrine #57

Open
krabouilleur opened this issue Apr 25, 2020 · 3 comments
Open

Proxies with Doctrine #57

krabouilleur opened this issue Apr 25, 2020 · 3 comments

Comments

@krabouilleur
Copy link

Hi !

When we use Doctrine wich returns proxies, the mapper could not map : it maps property to null.

Is there a solution ?

example dump doctrine result :

App\Entity\Company {#584
  -id: 81
  -secteur: Proxies\__CG__\App\Entity\Secteur {
    -id: 1
    -name: null
  }

dump($company->getSecteur->getName()) : returns a string

but the mapper found "null"

@mark-gerarts
Copy link
Owner

Hi @krabouilleur, yes this is a problem because Doctrine uses proxies to lazy-load entities. There are a few solutions:

  • Add fetch="EAGER" to your Doctrine mapping or query, this tells Doctrine to fully load the referenced objects. It is best to only do this on queries where you actually use the proxies, for performance reasons.
  • You can overwrite the property accessor to always load proxies as is done here
  • Add a beConstructedUsing where you load the entity, as is suggested here

By far the easiest way of doing this is to tell Doctrine to fetch the entities eagerly. Either on the mapping level if you always need them fully loaded, or on the single query if you only need it for one use case.

@jacksonveroneze
Copy link

Hello, I'm commenting on the issue because I have the updated version of lib and the problem persists. Someone managed to find a solution to the problem.

@mark-gerarts
Copy link
Owner

Hi @jacksonveroneze - sorry, I completely missed your question. Do you still have the same problem? If so, can you give some more context? This so we can make sure it is the same problem as the original question, and to provide a starting point for debugging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants