我想更新查询。首先,我有这样的数组:
array:5 [▼
0 => 2
1 => 9
2 => 10
3 => 531
4 => 635
]
名为$restaurants
。我想要的就是使用此阵列更新餐厅选择的字段。这是我的代码
第一条方法:
public function resetChosenRestaurants(array $restaurants) {
dd($restaurants);
$query = $this->_em->createQueryBuilder();
$query
->update($this->entityClass, "Restaurants")
->set("Restaurants.restaurantIsSelected", NULL)
->where($query->expr()->in('Restaurants.restaurantId', $restaurants))
->getQuery()->getSQL();
dd($query);
}
这是我的第二种方法:
public function resetChosenRestaurants(array $restaurants) {
$query = $this->_em->createQueryBuilder();
$query
->update($this->entityClass, "Restaurants")
->set("Restaurants.restaurantIsSelected", NULL)
->where("Restaurants.restaurantId IN :restaurantId")
->setParameter("restaurantId", $restaurants)
->getQuery()->execute();
dd($query);
}
我在两种情况下都有一个错误:
Error: Expected Literal, got 'WHERE'
任何建议?
使用param:
做到这一点public function resetChosenRestaurants(array $restaurants) {
$query = $this->_em->createQueryBuilder();
$query
->update($this->entityClass, "Restaurants")
->set("Restaurants.restaurantIsSelected", ':null')
->where($query->expr()->in('Restaurants.restaurantId', $restaurants))
->setParameter('null',null)
->getQuery()->execute();
}