Last active
August 29, 2015 13:56
-
-
Save fatorx/8967832 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
// use para classe doctrine | |
use Doctrine\ORM\Query\ResultSetMappingBuilder; | |
// código no método de consulta | |
$sql = " SELECT p.* " . | |
" FROM posts p ". | |
" INNER JOIN post_categories_has_posts pcp ON pcp.posts_id = p.id ". | |
" AND pcp.post_categories_id = ".$category->getId(). | |
" LIMIT ".$limit; | |
$rsm = new ResultSetMappingBuilder($this->em); | |
$rsm->addRootEntityFromClassMetadata('Blog\Entity\Post', 'p'); | |
$executeQuery = $this->em->createNativeQuery($sql, $rsm); | |
$result = $executeQuery->getOneOrNullResult(); // usado para limit 1 ou um resultado | |
$result = $executeQuery->getResult(); // usadoo para resultado em lista (array de entities) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment