Skip to content

Commit

Permalink
Fixed bug: Parent record is forced to be populated after a find opera…
Browse files Browse the repository at this point in the history
…tion
  • Loading branch information
jlorente committed Apr 22, 2015
1 parent e681272 commit 92f2a6a
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/ActiveRecordInheritanceTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,24 @@ private function _parent() {
throw new BaseException('Classes that use the \jlorente\db\ActiveRecordInheritanceTrait must implement \jlorente\db\ActiveRecordInheritanceInterface');
}
$pClass = static::extendsFrom();
if ($this->id !== null) {
$this->_parent = $pClass::findOne($this->{$this->parentAttribute()});
if ($this->getIsNewRecord() === false) {
$this->_parent = $this->parent;
} else {
$this->_parent = new $pClass();
}
}
return $this->_parent;
}

/**
* @inheritdoc
*/
public static function populateRecord($record, $row) {
parent::populateRecord($record, $row);

$record->_parent = $record->parent;
}

/**
* @inheritdoc
*/
Expand Down

0 comments on commit 92f2a6a

Please sign in to comment.