Sqlite SQL LITE+SYMFONY测试:SQLSTATE[HY000]:一般错误:1接近ON
我正在使用symfony+sqllite测试我的应用程序,我对ORM有问题。Doctrine在连接中使用双ON生成sql,类似于: 选择s0_u.config作为配置_0,选择s0_u.sensor_number作为sensor_number_1 来自传感器s0_ 左连接fos_用户f1_uu左连接工作者w2_uu在f1_uu.id上 =w2.id左加入f1上的经销商d3.id=s0上的经销商d3.id。所有者id=f1.id和f1.id状态!='d'左键加入用户组u4\uu打开 f1用户组id=u4用户id和u4用户状态!='d'在哪里s0_u.状态 = ? 和u4_4.id=?s0_u.device_id为NULL或s0_u.device_id=?并从fos_用户中选择用户\u组\u id,其中id=s0。所有者\u id= “1”和“s0”状态!='d' 它是关于:Sqlite SQL LITE+SYMFONY测试:SQLSTATE[HY000]:一般错误:1接近ON,sqlite,symfony,doctrine-orm,Sqlite,Symfony,Doctrine Orm,我正在使用symfony+sqllite测试我的应用程序,我对ORM有问题。Doctrine在连接中使用双ON生成sql,类似于: 选择s0_u.config作为配置_0,选择s0_u.sensor_number作为sensor_number_1 来自传感器s0_ 左连接fos_用户f1_uu左连接工作者w2_uu在f1_uu.id上 =w2.id左加入f1上的经销商d3.id=s0上的经销商d3.id。所有者id=f1.id和f1.id状态!='d'左键加入用户组u4\uu打开 f1用户组id
ON f1_.id = d3_.id ON (s0_.owner_id = f1_.id)
它会导致错误:
SQLSTATE[HY000]:一般错误:1近\开\:语法错误,类:条令\DBAL\Exception\SyntaxErrorException
我检查过,我知道SQLite不能与多个ONpostgresSQL一起工作,所以为什么doctrine在运行测试时生成它呢
Symfony表格对此负责:
$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;
},
]
);
编辑:
最后,我发现了我在下面的回答中描述的问题。谢谢您的时间。我终于在这张票上找到了问题: 没有必要这样做: ->leftJoinUser::类'o','WITH','s.owner=o.id' 应仅为: ->leftJoin's.owner','o' 实体已在此关系上定义了表与选定实体的关系 最后,此代码如下所示:
$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('s.owner', 'o')
->leftJoin('o.userGroup', 'g')
->andWhere('g.id = :userGroupId')
->andWhere('(s.device is null or s.device = :deviceId)')
->setParameter('userGroupId', $userGroup->getId())
->setParameter('deviceId', $device->getId());
return $qb;
},
]
);
最后我在这张票上发现了问题: 没有必要这样做: ->leftJoinUser::类'o','WITH','s.owner=o.id' 应仅为: ->leftJoin's.owner','o' 实体已在此关系上定义了表与选定实体的关系 最后,此代码如下所示:
$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('s.owner', 'o')
->leftJoin('o.userGroup', 'g')
->andWhere('g.id = :userGroupId')
->andWhere('(s.device is null or s.device = :deviceId)')
->setParameter('userGroupId', $userGroup->getId())
->setParameter('deviceId', $device->getId());
return $qb;
},
]
);
左连接选项卡4 d3_uon f1_uu.id=d3_uu.id ON s0_uu.o您有一个不带joinProvide PHP代码的ON负责运行此查询。左连接选项卡4 d3_uon f1_uu.id=d3_u.id ON-它在postgressqlI上工作。我添加了生成此查询的表单。左连接选项卡4 d3_uon f1_u.id=d3_u.id ON s0_u.o您有一个不带joinProvide PHP代码的ON负责运行此查询。f1上的LEFT JOIN tab4 d3_uu.id=d3_uu.id ON-它在postgressqlI上工作。添加了生成此查询的表单。