1
0
mirror of synced 2024-12-13 14:56:01 +03:00

Merge pull request #504 from nemekzg/DDC-1241

Proposed fix for DDC-1241
This commit is contained in:
Guilherme Blanco 2012-11-05 16:14:48 -08:00
commit 283ed55824
3 changed files with 20 additions and 4 deletions

View File

@ -160,13 +160,14 @@ class EntityRepository implements ObjectRepository, Selectable
* Finds a single entity by a set of criteria.
*
* @param array $criteria
* @param array|null $orderBy
* @return object
*/
public function findOneBy(array $criteria)
public function findOneBy(array $criteria, array $orderBy = null)
{
$persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);
return $persister->load($criteria, null, null, array(), 0, 1);
return $persister->load($criteria, null, null, array(), 0, 1, $orderBy);
}
/**

View File

@ -655,12 +655,13 @@ class BasicEntityPersister
* @param array $hints Hints for entity creation.
* @param int $lockMode
* @param int $limit Limit number of results
* @param array $orderBy Criteria to order by
* @return object The loaded and managed entity instance or NULL if the entity can not be found.
* @todo Check identity map? loadById method? Try to guess whether $criteria is the id?
*/
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = 0, $limit = null)
public function load(array $criteria, $entity = null, $assoc = null, array $hints = array(), $lockMode = 0, $limit = null, array $orderBy = null)
{
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc, $lockMode, $limit);
$sql = $this->_getSelectEntitiesSQL($criteria, $assoc, $lockMode, $limit, null, $orderBy);
list($params, $types) = $this->expandParameters($criteria);
$stmt = $this->_conn->executeQuery($sql, $params, $types);

View File

@ -344,6 +344,20 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals($addressId, $address->id);
}
/**
* @group DDC-1241
*/
public function testFindOneByOrderBy()
{
$this->loadFixture();
$repos = $this->_em->getRepository('Doctrine\Tests\Models\CMS\CmsUser');
$userAsc = $repos->findOneBy(array(), array("username" => "ASC"));
$userDesc = $repos->findOneBy(array(), array("username" => "DESC"));
$this->assertNotSame($userAsc, $userDesc);
}
/**
* @group DDC-817
*/