Permalink
Browse files

Add new termination method: exists()

Closes #427.
Issue URL: #427.
  • Loading branch information...
1 parent 363fce3 commit 754adbf1cbd912b0b03cfccb6adc213dc82efbe3 @willdurand willdurand committed Aug 6, 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 754adbf

Please sign in to comment.