Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #438 from willdurand/exists

Add new termination method: exists()
  • Loading branch information...
commit 92d2677312567634d24b3ce8c0d1615cb2872d9a 2 parents 363fce3 + 754adbf
@willdurand willdurand authored
View
9 runtime/lib/query/ModelCriteria.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);
+ }
}
View
13 test/testsuite/runtime/query/ModelCriteriaTest.php
@@ -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.
Something went wrong with that request. Please try again.