mirror of
https://github.com/doctrine/orm.git
synced 2026-03-23 22:42:18 +01:00
Coalesce in JoinColumn #5530
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 @michsk on GitHub (May 9, 2017).
Originally assigned to: @Ocramius on GitHub.
Do we at this moment have a way to use coalesce in the join column for relations?
For example a car has many parts. A car can have a relation to a car. I want to make demo cars, which refer to another car (the original car). But i do not want to copy all the parts of the car. So i would like to join using Coalesce.
join part.car_id = coalesce(car.car_id, car.id)So we would use the coalesce to first check if the car has a car_id, referring to the original car, if so, its a demo car and we use the car id of the original car for loading the parts. If not than use the car's own id. For example when calling the original car.If this would not be possible using the Annotations. Would it be possible in a different way?
@michsk commented on GitHub (May 9, 2017):
Maybe have DemoCar, and use the Overwrite annotation to overwrite the join column? Guess that would be the best way to do this.
@Ocramius commented on GitHub (May 9, 2017):
@Michal-sk I don't understand the scenario: what would this look like, in entities?
Also, maybe I'm naive, but I've never seen a coalesce join. The ORM always builds associations towards identifiers only, so
car_id, being a foreign key, and not an identifier, is an invalid referenced column.@michsk commented on GitHub (May 10, 2017):
Got it.