Permalink
Browse files

Merge pull request #504 from nemekzg/DDC-1241

Proposed fix for DDC-1241
  • Loading branch information...
guilhermeblanco committed Nov 6, 2012
2 parents 6949a95 + 9705ee8 commit 283ed55824b7c713611e4b1e336551be805c48b5
@@ -160,13 +160,14 @@ public function findBy(array $criteria, array $orderBy = null, $limit = null, $o
* 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);
}
/**
@@ -655,12 +655,13 @@ public function getOwningTable($fieldName)
* @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);
@@ -344,6 +344,20 @@ public function testFindOneByAssociationKey()
$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
*/

0 comments on commit 283ed55

Please sign in to comment.