<?php namespace Lc\CaracoleBundle\Repository; use Lc\CaracoleBundle\Model\Merchant\MerchantInterface; use Lc\CaracoleBundle\Model\Section\SectionInterface; trait SectionRepositoryQueryTrait { protected bool $isJoinSection = false; public function filterBySection(SectionInterface $section) { return $this->andWhereSection($this->id, $section); } public function filterByMerchantViaSection(MerchantInterface $merchant) { $this->joinSection(); return $this->andWhere('s.merchant = :merchant') ->setParameter('merchant', $merchant); } public function joinSection(): self { if (!$this->isJoinSection) { $this->isJoinSection = true; return $this ->leftJoin('.section', 's'); } return $this; } }