Symfony o、 只需使用->where'lh.user NOT NULL'代替have,它就可以工作了。 class User { // ... /** * @ORM\OneToMany(targetEntity="Registra
o、 只需使用->where'lh.user NOT NULL'代替have,它就可以工作了。Symfony o、 只需使用->where'lh.user NOT NULL'代替have,它就可以工作了。 class User { // ... /** * @ORM\OneToMany(targetEntity="Registra,symfony,doctrine-orm,pagination,Symfony,Doctrine Orm,Pagination,o、 只需使用->where'lh.user NOT NULL'代替have,它就可以工作了。 class User { // ... /** * @ORM\OneToMany(targetEntity="Registration", mappedBy="user") */ private $registrations; // ... } $qb = $this->createQueryBuilder(); $qu
class User
{
// ...
/**
* @ORM\OneToMany(targetEntity="Registration", mappedBy="user")
*/
private $registrations;
// ...
}
$qb = $this->createQueryBuilder();
$query = $qb
->select('u')
->add('from', '\YourBundle\ORM\Model\User u')
->leftJoin('\YourBundle\ORM\Model\Registration', 'r', 'WITH', 'u.id = r.user')
->groupBy('u.id')
->having($qb->expr()->gte($qb->expr()->count('u.registrations'), '1')
->getQuery();
$qb = $this->createQueryBuilder();
$query = $qb
->select('u')
->add('from', '\YourBundle\ORM\Model\User u LEFT JOIN u.registrations r')
->groupBy('u.id')
->having($qb->expr()->gte($qb->expr()->count('r'), '1')
->getQuery();
$paginator = new Paginator;
// determine the count of the entire result set
$count = $entityManager
->createQuery('SELECT COUNT(c) FROM Entity\CompositeKey c')
->getSingleScalarResult();
// create a query to be used with the paginator, and specify a hint
$query = $entityManager
->createQuery('SELECT c FROM Entity\CompositeKey c')
->setHint(
'knp_paginator.count',
$count
);
// paginate, and set "disctinct" option to false
$pagination = $paginator->paginate(
$query,
1,
10,
array(
'distinct' => false,
)
);
$queryBuilder // The query builder already has the other entities added.
->innerJoin('r.user', 'user')
;
$mapping['fieldName'] = 'user';
$mapping['targetEntity'] = '\YourBundle\ORM\Model\User';
$mapping['sourceEntity'] = '\YourBundle\ORM\Model\Registration';
$mapping['sourceToTargetKeyColumns'] = array('user' => 'id');
$mapping['targetToSourceKeyColumns'] = array('id' => 'user');
$mapping['fetch'] = 2;
$mapping['joinColumns'] = array(
array(
'name' => 'user',
'unique' => false,
'nullable' => false,
'onDelete' => null,
'columnDefinition' => null,
'referencedColumnName' => 'id',
)
);
$mapping['mappedBy'] = 'user';
$mapping['inversedBy'] = null; // User doesn't have to link to registrations
$mapping['orphanRemoval'] = false;
$mapping['isOwningSide'] = true;
$mapping['type'] = ClassMetadataInfo::MANY_TO_ONE;
$vm = $this->em->getClassMetadata('YourBundle:Registration');
$vm->associationMappings["user"] = $mapping;