Skip to content

Commit 92f2a6a

Browse files
committed
Fixed bug: Parent record is forced to be populated after a find operation
1 parent e681272 commit 92f2a6a

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/ActiveRecordInheritanceTrait.php

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,15 +86,24 @@ private function _parent() {
8686
throw new BaseException('Classes that use the \jlorente\db\ActiveRecordInheritanceTrait must implement \jlorente\db\ActiveRecordInheritanceInterface');
8787
}
8888
$pClass = static::extendsFrom();
89-
if ($this->id !== null) {
90-
$this->_parent = $pClass::findOne($this->{$this->parentAttribute()});
89+
if ($this->getIsNewRecord() === false) {
90+
$this->_parent = $this->parent;
9191
} else {
9292
$this->_parent = new $pClass();
9393
}
9494
}
9595
return $this->_parent;
9696
}
9797

98+
/**
99+
* @inheritdoc
100+
*/
101+
public static function populateRecord($record, $row) {
102+
parent::populateRecord($record, $row);
103+
104+
$record->_parent = $record->parent;
105+
}
106+
98107
/**
99108
* @inheritdoc
100109
*/

0 commit comments

Comments
 (0)