Skip to content

Commit 7f6f286

Browse files
authored
Fixed bug getting parent attribute value
1 parent ff20d99 commit 7f6f286

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

src/ActiveRecordInheritanceTrait.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function getParent($recalculate = false)
9292
throw new BaseException('Classes that use the \jlorente\db\ActiveRecordInheritanceTrait must implement \jlorente\db\ActiveRecordInheritanceInterface');
9393
}
9494
$pClass = static::extendsFrom();
95-
if ($this->getParentAttributeValue() && $this->getIsNewRecord() === false && ($parent = $this->_parent()->one())) {
95+
if ($this->getParentAttributeValue() && ($parent = $this->_parent()->one())) {
9696
$this->_parent = $parent;
9797
} else {
9898
$this->_parent = new $pClass();
@@ -470,8 +470,6 @@ public function loadDefaultValues($skipIfSet = true)
470470
*/
471471
public function getParentAttributeValue()
472472
{
473-
$ownAttributes = $this->attributes();
474-
$parentAttribute = $this->parentAttribute();
475-
return isset($ownAttributes[$parentAttribute]) ? $ownAttributes[$parentAttribute] : null;
473+
return $this->{$this->parentAttribute()};
476474
}
477475
}

0 commit comments

Comments
 (0)