Skip to content

Instantly share code, notes, and snippets.

View wbrframe's full-sized avatar
:accessibility:
Open to work

Yevhenii Vaskevych wbrframe

:accessibility:
Open to work
View GitHub Profile
@wbrframe
wbrframe / gist:6ffe6292345024fb059d4693ffd346ca
Created September 5, 2019 12:52
Doctrine custom DQL string function for PostgreSQL string_agg with supports DISTINCT and ORDER BY clause
<?php
namespace App\DQL;
use Doctrine\ORM\Query\AST\Functions\FunctionNode;
use Doctrine\ORM\Query\AST\Literal;
use Doctrine\ORM\Query\AST\OrderByClause;
use Doctrine\ORM\Query\AST\PathExpression;
use Doctrine\ORM\Query\Lexer;
use Doctrine\ORM\Query\Parser;
@wbrframe
wbrframe / gist:092c9de78b8f9c68825b7d018e90fd92
Last active August 8, 2019 09:57
Generate microseconds for exists dates that without microseconds
# For example, you store dates in the type `timestamp with timezone`:
2019-08-04 11:13:17+00
# This query generates randomly microseconds for a date:
UPDATE <table> SET <field> = TO_TIMESTAMP(replace(to_char(<field>, 'YYYY-MM-DD HH24:MI:SS.SS%m%OF'), '%m%', (floor(random()*(10000-1+1))+1)::text), 'YYYY-MM-DD HH24:MI:SS.US')
$reference = $em->getPartialReference('MyApp\Domain\User', 1);
<?php $q = $em->createQuery("select partial u.{id,name} from MyApp\Domain\User u");
$item = $em->getReference('MyProject\Model\Item', $itemId);
$cart->addItem($item);
Collection#contains($entity)
Collection#containsKey($key) (доступно начиная с Doctrine 2.5)
Collection#count()
Collection#get($key) (доступно начиная с Doctrine 2.4)
Collection#slice($offset, $length = null)
public function testIdentityMapRepositoryFindBy()
{
$repository = $this->entityManager->getRepository('Person');
$objectA = $repository->findOneBy(array('name' => 'Benjamin'));
$objectB = $repository->findOneBy(array('name' => 'Benjamin'));
$this->assertSame($objectA, $objectB);
}
public function testIdentityMap()
{
$objectA = $this->entityManager->find('EntityName', 1);
$objectB = $this->entityManager->find('EntityName', 1);
$this->assertSame($objectA, $objectB)
}