Permalink
Browse files

Merge pull request #461 from havvg/master

allow unsetting lazy load columns without loading
  • Loading branch information...
2 parents 09760d7 + 2345aaa commit bfb8055fbcc430cc84d5d4cfbe35dd2a4c4745d1 @willdurand willdurand committed Sep 10, 2012
@@ -1417,6 +1417,11 @@ protected function addMutatorOpenBody(&$script, Column $col)
$cfc = $col->getPhpName();
if ($col->isLazyLoad()) {
$script .= "
+ // Allow unsetting the lazy loaded column even when its not loaded.
+ if (!\$this->".$clo."_isLoaded && \$v === null) {
+ \$this->modifiedColumns[] = ".$this->getColumnConstant($col).";
+ }
+
// explicitly set the is-loaded flag to true for this lazy load col;
// it doesn't matter if the value is actually set or not (logic below) as
// any attempt to set the value means that no db lookup should be performed
@@ -77,4 +77,20 @@ public function testLazyLoadedColumnsWithDefaultRequireAnAdditionalQueryOnGetter
$this->assertEquals('hello', $obj2->getBaz($con));
$this->assertEquals($count + 1, $con->getQueryCount());
}
+
+ public function testLazyLoadedColumnsMayBeUnsetWithoutLoading()
+ {
+ $con = Propel::getconnection(LazyLoadActiveRecordPeer::DATABASE_NAME);
+ $con->useDebug(true);
+ $obj = new LazyLoadActiveRecord();
+ $obj->setBar('hello');
+ $obj->save($con);
+ LazyLoadActiveRecordPeer::clearInstancePool();
+ $obj2 = LazyLoadActiveRecordQuery::create()->findPk($obj->getId(), $con);
+ $obj2->setBar(null);
+ $obj2->save();
+ LazyLoadActiveRecordPeer::clearInstancePool();
+ $obj3 = LazyLoadActiveRecordQuery::create()->findPk($obj->getId(), $con);
+ $this->assertNull($obj3->getBar());
+ }
}

0 comments on commit bfb8055

Please sign in to comment.