Skip to content
Permalink
Browse files

FIX No longer caching has_one after ID change

  • Loading branch information...
dhensby committed Jun 16, 2015
1 parent 27f272d commit 6169bf2760366b0aebf255c973803621472ce1fb
Showing with 13 additions and 0 deletions.
  1. +4 −0 model/DataObject.php
  2. +9 −0 tests/model/DataObjectTest.php
@@ -2316,6 +2316,10 @@ public function isChanged($fieldName = null, $changeLevel = 1) {
* @return DataObject $this
*/
public function setField($fieldName, $val) {
//if it's a has_one component, destroy the cache
if (substr($fieldName, -2) == 'ID') {
unset($this->components[substr($fieldName, 0, -2)]);
}
// Situation 1: Passing an DBField
if($val instanceof DBField) {
$val->Name = $fieldName;
@@ -311,6 +311,7 @@ public function testHasManyRelationships() {
public function testHasOneRelationship() {
$team1 = $this->objFromFixture('DataObjectTest_Team', 'team1');
$player1 = $this->objFromFixture('DataObjectTest_Player', 'player1');
$player2 = $this->objFromFixture('DataObjectTest_Player', 'player2');
// Add a captain to team 1
$team1->setField('CaptainID', $player1->ID);
@@ -325,6 +326,14 @@ public function testHasOneRelationship() {
'Player 1 is the captain');
$this->assertEquals($team1->getComponent('Captain')->FirstName, 'Player 1',
'Player 1 is the captain');
$team1->CaptainID = $player2->ID;
$team1->write();
$this->assertEquals($player2->ID, $team1->Captain()->ID);
$this->assertEquals($player2->ID, $team1->getComponent('Captain')->ID);
$this->assertEquals('Player 2', $team1->Captain()->FirstName);
$this->assertEquals('Player 2', $team1->getComponent('Captain')->FirstName);
}
/**

0 comments on commit 6169bf2

Please sign in to comment.
You can’t perform that action at this time.