public function findByUniqueAttribute(
        FamilyInterface $family,
        AttributeInterface $attribute,
        $reference,
        $partialLoad = false
    ) {
        if (!$attribute->isUnique()) {
            throw new \LogicException("Cannot find data based on a non-unique attribute '{$attribute->getCode()}'");
        }
        $dataBaseType = $attribute->getType()->getDatabaseType();
        $qb = $this->createQueryBuilder('e');
        $joinCondition = "(identifier.attributeCode = :attributeCode AND identifier.{$dataBaseType} = :reference)";
        $qb
            ->join('e.values', 'identifier', Join::WITH, $joinCondition)
            ->where('e.family = :familyCode')
            ->setParameters(
                [
                    'attributeCode' => $attribute->getCode(),
                    'reference' => $reference,
                    'familyCode' => $family->getCode(),
                ]
            );

        if ($partialLoad) {
            return $this->executeWithPartialLoad($qb);
        }

        return $qb->getQuery()->getOneOrNullResult();
    }
public function findByUniqueAttribute(
        FamilyInterface $family,
        AttributeInterface $attribute,
        $reference,
        $partialLoad = false
    ) {
        if (!$attribute->isUnique()) {
            throw new \LogicException("Cannot find data based on a non-unique attribute '{$attribute->getCode()}'");
        }
        $dataBaseType = $attribute->getType()->getDatabaseType();
        $qb = $this->createQueryBuilder('e');
        $joinCondition = "(identifier.attributeCode = :attributeCode AND identifier.{$dataBaseType} = :reference)";
        $qb
            ->join('e.values', 'identifier', Join::WITH, $joinCondition)
            ->where('e.family = :familyCode')
            ->setParameters(
                [
                    'attributeCode' => $attribute->getCode(),
                    'reference' => $reference,
                    'familyCode' => $family->getCode(),
                ]
            );

        if ($partialLoad) {
            return $this->executeWithPartialLoad($qb);
        }

        return $qb->getQuery()->getOneOrNullResult();
    }
public function findByUniqueAttribute ( FamilyInterface $ family , AttributeInterface $ attribute , $ reference , $ partialLoad = false ) { if ( ! $ attribute -> isUnique ( ) ) { throw new \ LogicException ( "Cannot find data based on a non-unique attribute '{$attribute->getCode()}'" ) ; } $ dataBaseType = $ attribute -> getType ( ) -> getDatabaseType ( ) ; $ qb = $ this -> createQueryBuilder ( 'e' ) ; $ joinCondition = "(identifier.attributeCode = :attributeCode AND identifier.{$dataBaseType} = :reference)" ; $ qb -> join ( 'e.values' , 'identifier' , Join :: WITH , $ joinCondition ) -> where ( 'e.family = :familyCode' ) -> setParameters ( [ 'attributeCode' => $ attribute -> getCode ( ) , 'reference' => $ reference , 'familyCode' => $ family -> getCode ( ) , ] ) ; if ( $ partialLoad ) { return $ this -> executeWithPartialLoad ( $ qb ) ; } return $ qb -> getQuery ( ) -> getOneOrNullResult ( ) ; }
Find a data based on a unique attribute

@param FamilyInterface    $family
@param AttributeInterface $attribute
@param string|int         $reference
@param bool               $partialLoad

@throws \LogicException
@throws \Doctrine\ORM\ORMException
@throws NonUniqueResultException

@return DataInterface|null
Find a data based on a unique attribute