Permalink
Browse files

Merge pull request #438 from willdurand/exists

Add new termination method: exists()
  • Loading branch information...
2 parents 363fce3 + 754adbf commit 92d2677312567634d24b3ce8c0d1615cb2872d9a @willdurand willdurand committed Aug 7, 2012
Showing with 22 additions and 0 deletions.
  1. +9 −0 runtime/lib/query/ModelCriteria.php
  2. +13 −0 test/testsuite/runtime/query/ModelCriteriaTest.php
@@ -2247,4 +2247,13 @@ public function explain($con = null)
throw new PropelException('Unable to execute query explain plan', $e);
}
}
+
+ /**
+ * @param PropelPDO $con = null
+ * @return boolean
+ */
+ public function exists($con = null)
+ {
+ return 0 !== $this->count($con);
+ }
}
@@ -2480,6 +2480,19 @@ public function testOrderByWithInsensitiveCase()
$c->orderBy('TITLE');
$this->assertCriteriaTranslation($c, $sql, $params);
}
+
+ public function testExists()
+ {
+ $c = new ModelCriteria('bookstore', 'Book', 'b');
+ $this->assertTrue($c->exists());
+ }
+
+ public function testExistsWithNonExistentCondition()
+ {
+ $c = new ModelCriteria('bookstore', 'Book', 'b');
+ $c->where('b.Title = ?', 'jenexistepas');
+ $this->assertFalse($c->exists());
+ }
}
class TestableModelCriteria extends ModelCriteria

0 comments on commit 92d2677

Please sign in to comment.