in句でサブクエリを使って一括更新
public function updatePaymentStatus(?array $ids,?int $status){
$inquirySubQb = $this->_em->createQueryBuilder()
->select('i.id')
->from(Inquiry::class, 'i');
$inquirySubQb->andWhere($inquirySubQb->expr()->in('i.id', $ids));
$qb = $this->createQueryBuilder('e')
->update()
->set('e.paymentStatus', $status);
$qb->andWhere($qb->expr()->in('e.inquiry', $inquirySubQb->getDQL()));
$query = $qb->getQuery();
return $query->getResult();
}
サブクエリを使って同一グループ内で最新のデータを取得
$qb = $this->createQueryBuilder('i');
$subQb = $this->_em->createQueryBuilder()
->select('max(subi.updateDate)')
->from(Inquiry::class, 'subi')
->where('i.senderMail = subi.senderMail');
$qb->andWhere("i.updateDate = ({$subQb->getDQL()})");