This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Other stuff. | |
* | |
* @ORM\Table("user_extra") | |
* @ORM\Entity() | |
* @ORM\HasLifecycleCallbacks() | |
*/ | |
class LazyUserData |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// in the controller | |
$user = Customer::isCustomer($this->getUser()); | |
// in the entity | |
/** | |
* @param UserInterface $user | |
* | |
* @return Customer|null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// in the controller | |
$user->addCreditCard(new CreditCard()); | |
// this actually shows up in the form. | |
$user->getCreditCards()[0]->setCvv(123); | |
// in the outer form type | |
$builder->add( | |
'credit_card', | |
CollectionType::class, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Parent{ | |
private static $attribute; | |
public getAttribute(){ | |
return self::$attribute; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mybundle.repository.mymodelrepo: | |
class: MyBundle\Repository\MyModelRepository | |
calls: | |
- [ unpack, [@=service('snc_redis.default').get('MyModel')] ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$qb = $this->createQueryBuilder('l') | |
->select('l, c') | |
->join('l.country', 'c') | |
->where($expr->in('l.id', '?1')) | |
->setParameter(1, $ids); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |