yii2-activerecord-inheritance icon indicating copy to clipboard operation
yii2-activerecord-inheritance copied to clipboard

Not compatible with yii2 2.0.45

Open goraxan opened this issue 2 years ago • 1 comments

When trying to access a parent property for a newly created ActiveRecord, the whole server crashes without any error. It's working fine with the 2.0.44 version. I've tried with php 7.4 and 8.0, same results.

This access https://github.com/jlorente/yii2-activerecord-inheritance/blob/master/src/ActiveRecordInheritanceTrait.php#L95 causes the cash. While in the 2.0.44 version it returns null (because the entry is not saved yet) in 2.0.45 it crashes.

Changing the function to this might work:

if ($this->getIsNewRecord() === true) {
    $this->_parent = new $pClass();
} else {
    $parent = $this->_parent()->one();
    if($parent !== null)
        $this->_parent = $parent;
}

To reproduce:

$admin = new Admin();
$admin->username = 'al-acran'; <-- crash without any error

This works fine;

$admin = Admin::find()->one();
$admin->username = 'al-acran';

Any thoughts on this?

goraxan avatar Mar 10 '22 11:03 goraxan