0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

symfony4 レポジトリで使うサブクエリ

Last updated at Posted at 2020-09-20

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()})");
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?