I'm using symfony+sqllite to test my application and I have issue with ORM. Doctrine generates sql with double ON in JOIN, something like:
SELECT s0_.config AS config_0, s0_.sensor_number AS sensor_number_1 FROM sensors s0_ LEFT JOIN fos_user f1_ LEFT JOIN worker w2_ ON f1_.id = w2_.id LEFT JOIN dealer d3_ ON f1_.id = d3_.id ON (s0_.owner_id = f1_.id) AND (f1_.status != 'd') LEFT JOIN user_groups u4_ ON (f1_.user_group_id = u4_.id) AND (u4_.status != 'd') WHERE (s0_.status = ? AND u4_.id = ? AND ((s0_.device_id IS NULL OR s0_.device_id = ?))) AND ((select user_group_id from fos_user where id = s0_.owner_id) = '1') AND (s0_.status != 'd')
it is about:
ON f1_.id = d3_.id ON (s0_.owner_id = f1_.id)
it cause error:
SQLSTATE[HY000]: General error: 1 near \"ON\": syntax error","class":"Doctrine\DBAL\Exception\SyntaxErrorException"
I checked and I'm aware that SQLite doesn't work with more than one "ON"(postgresSQL works), so why doctrine generates it when run tests.
Symfony form responsible for this:
$builder->add(
'sensors',
EntityType::class,
[
'class' => Sensors::class,
'label' => 'form.assigned-sensors',
'required' => false,
'multiple' => true,
'by_reference' => false,
'query_builder' => function (EntityRepository $er) use ($device, $userGroup) {
$qb = $er->createQueryBuilder('s')
->leftJoin(User::class, 'o', 'WITH', 's.owner = o.id')
->leftJoin(UserGroups::class, 'g', 'WITH', 'o.userGroup = g.id')
->where('s.status = :status')
->andWhere('g.id = :userGroupId')
->andWhere('(s.device is null or s.device = :deviceId)')
->setParameter('status', 'a')
->setParameter('deviceId', $device->getId())
->setParameter('userGroupId', $userGroup->getId());
return $qb;
},
]
);
EDIT:
Finally i found the issue as described in my answer below. Thanks for your time.