Skip to content

Instantly share code, notes, and snippets.

<?php
namespace MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
/**
* MyEntity.
<?php
namespace MyBundle\Entity;
use Doctrine\ORM\Mapping as ORM;
/**
* RecentSearch
*
* @ORM\Table("recent_search")
<?php
namespace MyBundle\Repository;
use MyBundle\Entity\Customer;
use Doctrine\ORM\EntityRepository;
class RecentSearchRepository extends EntityRepository
{
public function findRecentByUser(Customer $user)
SELECT l.*, MAX(s.sale_ts) FROM location AS `l` LEFT JOIN sales AS `s` ON l.id = s.location_id GROUP BY(s.location_id);
@ABM-Dan
ABM-Dan / qb.php
Last active January 27, 2016 22:27
<?php
// Trying to emulate
// SELECT l.*, MAX(s.sale_ts) FROM location AS `l` LEFT JOIN sales AS `s` ON l.id = s.location_id GROUP BY(s.location_id);
// But the group selects the last result.
$qb = $this->createQueryBuilder('l')
->leftJoin('l.sales', 's')
->where('l.is_active = 1')
->orderBy('l.id', 'ASC')
->addOrderBy('s.sale_ts', 'DESC')
->groupBy('l.id');
$qb = $this->createQueryBuilder('l')
->leftJoin('l.sales', 's')
->where('l.is_active = 1')
->andWhere('s.sale_ts = (SELECT MAX(s2.sale_ts) FROM MyBundle:Sale s2 WHERE s2.location = l)')
->orderBy('l.id', 'ASC');
<?php
$qb = $this->createQueryBuilder('l')
->select('l, c')
->join('l.country', 'c')
->where($expr->in('l.id', '?1'))
->setParameter(1, $ids);
mybundle.repository.mymodelrepo:
class: MyBundle\Repository\MyModelRepository
calls:
- [ unpack, [@=service('snc_redis.default').get('MyModel')] ]
<?php
namespace MyBundle\Form\Type;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints as Assert;
class MyFormType extends AbstractType implements ContainerAwareInterface
<?php
class Parent{
private static $attribute;
public getAttribute(){
return self::$attribute;
}
}