From fe09c720833c40bf0588441ccfc1b578501bc2ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 23 Nov 2020 14:20:23 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Database/Base/BaseActiveRecord.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index 26d65724..86940a3e 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace Database\Base; +use HttpServer\Http\Context; use Snowflake\Abstracts\Component; use Snowflake\Core\JSON; use Database\ActiveQuery; @@ -57,15 +58,19 @@ abstract class BaseActiveRecord extends Component implements IOrm, \ArrayAccess protected array $actions = []; - /** @var Relation */ - protected $_relation = []; + protected ?Relation $_relation; /** * @throws Exception */ public function init() { - $this->_relation = Snowflake::createObject(Relation::className()); + if (!Context::hasContext(Relation::class)) { + $relation = Snowflake::createObject(Relation::class); + $this->_relation = Context::setContext(Relation::class, $relation); + } else { + $this->_relation = Context::getContext(Relation::class); + } } /**