Skip to content

Commit

Permalink
Merge pull request #438 from willdurand/exists
Browse files Browse the repository at this point in the history
Add new termination method: exists()
  • Loading branch information
willdurand committed Aug 7, 2012
2 parents 363fce3 + 754adbf commit 92d2677
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
9 changes: 9 additions & 0 deletions runtime/lib/query/ModelCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
13 changes: 13 additions & 0 deletions test/testsuite/runtime/query/ModelCriteriaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 92d2677

Please sign in to comment.