mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
How to COALCASE relation? #6060
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 @BonBonSlick on GitHub (Sep 11, 2018).
Originally assigned to: @Ocramius on GitHub.
Support Question
Example, User entity has 3 fields, A,B,C;All are relations, 2 always null, 1 is always id, let it be type of user details object.
How to select all users and get it is details from 1 of the relations? Because it is 3 different tables to join and it depends on which field is not null. Eg
it said
User has no association named relationNotNullOk, lets try this
we have
[Syntax Error] line 0, col 403: Error: Expected Doctrine\ORM\Query\Lexer::T_ALIASED_NAME, got 'COALESCE'How to do it right way?
@Ocramius commented on GitHub (Sep 11, 2018):
You'd simply
LEFT JOINall 3 associations, and then have all 3 fields populated with either the associated entoty ornull: then you'll deal with the coalescing in an accessor.Note that doctrine associations are statically defined, and cannot be hydrated dynamically.
@BonBonSlick commented on GitHub (Sep 13, 2018):
@Ocramius thanks)
Loading 3 tables with thousands records not good option)