Merge pull request #504 from nemekzg/DDC-1241
Proposed fix for DDC-1241
This commit is contained in:
commit
283ed55824
@ -160,13 +160,14 @@ class EntityRepository implements ObjectRepository, Selectable
|
|||||||
* Finds a single entity by a set of criteria.
|
* Finds a single entity by a set of criteria.
|
||||||
*
|
*
|
||||||
* @param array $criteria
|
* @param array $criteria
|
||||||
|
* @param array|null $orderBy
|
||||||
* @return object
|
* @return object
|
||||||
*/
|
*/
|
||||||
public function findOneBy(array $criteria)
|
public function findOneBy(array $criteria, array $orderBy = null)
|
||||||
{
|
{
|
||||||
$persister = $this->_em->getUnitOfWork()->getEntityPersister($this->_entityName);
|
$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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -655,12 +655,13 @@ class BasicEntityPersister
|
|||||||
* @param array $hints Hints for entity creation.
|
* @param array $hints Hints for entity creation.
|
||||||
* @param int $lockMode
|
* @param int $lockMode
|
||||||
* @param int $limit Limit number of results
|
* @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.
|
* @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?
|
* @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);
|
list($params, $types) = $this->expandParameters($criteria);
|
||||||
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
$stmt = $this->_conn->executeQuery($sql, $params, $types);
|
||||||
|
|
||||||
|
@ -344,6 +344,20 @@ class EntityRepositoryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals($addressId, $address->id);
|
$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
|
* @group DDC-817
|
||||||
*/
|
*/
|
||||||
|
Loading…
Reference in New Issue
Block a user