Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix: port PR #287 from Propel #168

Merged
merged 1 commit into from

2 participants

@K-Phoen

Propel2 issue: #143
Original PR: propelorm/Propel#287

@willdurand willdurand merged commit c8a5e6e into propelorm:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 30, 2012
  1. @K-Phoen

    Fix: port PR #287 from Propel

    K-Phoen authored
This page is out of date. Refresh to see the latest.
View
4 src/Propel/Runtime/Query/ModelCriteria.php
@@ -1218,6 +1218,10 @@ public function findOne($con = null)
*/
public function findOneOrCreate($con = null)
{
+ if ($this->joins) {
+ throw new PropelException('findOneOrCreate() cannot be used on a query with a join, because Propel cannot transform a SQL JOIN into a subquery. You should split the query in two queries to avoid joins.');
+ }
+
if (!$ret = $this->findOne($con)) {
$class = $this->getModelName();
$obj = new $class();
View
13 tests/Propel/Tests/Runtime/Query/ModelCriteriaTest.php
@@ -1660,6 +1660,19 @@ public function testFindOneOrCreateExists()
$this->assertEquals(125, $book->getPrice(), 'findOneOrCreate() returns a populated objects based on the conditions');
}
+ /**
+ * @expectedException Propel\Runtime\Exception\PropelException
+ */
+ public function testFindOneOrCreateThrowsExceptionWhenQueryContainsJoin()
+ {
+ $book = BookQuery::create('b')
+ ->filterByPrice(125)
+ ->useAuthorQuery()
+ ->filterByFirstName('Leo')
+ ->endUse()
+ ->findOneOrCreate();
+ }
+
public function testFindOneOrCreateMakesOneQueryWhenRecordNotExists()
{
$con = Propel::getServiceContainer()->getConnection(BookPeer::DATABASE_NAME);
Something went wrong with that request. Please try again.