mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-3959: Option to use LEFT JOIN instead of INNER JOIN with findAll() method. #4841
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Oct 23, 2015).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user greekatrina:
I have a User and Company entity. Each User belongs to a Company. Here are my entities (shortened):
When I was testing my production code, I forgot to add a company to the company table. So, when I did a basic $entityManager->getRepository('App/Model/Entity/User')->findAll(); to make sure my database was connecting correctly, it returned an empty array, even though I had a user in there.
I dug a little bit to find the SQL it was outputting, which was this:
I realized the INNER JOIN was the reason I wasn't getting any users. Now I'm curious what causes Doctrine to use the INNER JOIN? Is it due to nullable=false for the company attribute in the User entity, or something else?
Is there another way to get all of the users, even if they don't belong to a company?
@beberlei commented on GitHub (Feb 16, 2020):
Yes, this is because of the
nullable=false. If you havenullable=truethen it will use aLEFT JOIN.