Semantic errors using AddSelect
yaffol opened this issue · 2 comments
Hi, I've just started to use AddSelect in a project, and I'm running into semantic errors:
[Semantical Error] line 0, col 12 near 'ev, e.eventCol,': Error: Class App\Entity\EventColumnInstance has no field or association named ev
The Spec I'm using is:
class JoinAndSelectEvents extends BaseSpecification
{
public function getSpec()
{
return Spec::andX(
Spec::join('event', 'ev'),
Spec::addSelect('ev')
);
}
}
Which I've tracked down to the Field class always prepending the dql alias to the field name when it is called from ArgumentToSelectionConverter::toSelection
.
The DQL which does not work is:
SELECT e, e.ev, e.eventCol FROM App\Entity\EventColumnInstance e INNER JOIN e.event ev INNER JOIN e.eventColumn eventCol
The DQL which does work is:
SELECT e, ev, eventCol FROM App\Entity\EventColumnInstance e INNER JOIN e.event ev INNER JOIN e.eventColumn eventCol
I've created a bugfix branch which works around the problem, to the extent that I can use the latest version in my project, but I suspect there is a neater way of resolving the issue.
Thank you for message.
In the case you described, you need to use the Spec::selectEntity()
function.
// DQL: SELECT e, ev FROM ...
Spec::andX(
Spec::join('event', 'ev'),
Spec::addSelect(Spec::selectEntity('ev'))
)
See the guide for more details.
Thank you - I had forgotten about the new selectEntity method - many thanks for drawing my attention back to it.