Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

allow unsetting lazy load columns without loading #461

Merged
merged 1 commit into from

2 participants

@havvg

No description provided.

@willdurand willdurand merged commit bfb8055 into from
@willdurand
Owner

Great, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 6, 2012
  1. @havvg
This page is out of date. Refresh to see the latest.
View
5 generator/lib/builder/om/PHP5ObjectBuilder.php
@@ -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
View
16 test/testsuite/generator/builder/om/GeneratedObjectLazyLoadTest.php
@@ -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());
+ }
}
Something went wrong with that request. Please try again.