diff --git a/Annotation/Model/Relation.php b/Annotation/Model/Relation.php new file mode 100644 index 00000000..4bfe5025 --- /dev/null +++ b/Annotation/Model/Relation.php @@ -0,0 +1,43 @@ +setRelate($this->name, $method); + + return parent::execute($handler); + } + +} diff --git a/Database/ActiveQuery.php b/Database/ActiveQuery.php index 12c34e46..c90885ec 100644 --- a/Database/ActiveQuery.php +++ b/Database/ActiveQuery.php @@ -227,10 +227,10 @@ class ActiveQuery extends Component implements ISqlBuilder /** - * @param $model - * @return mixed + * @param ActiveRecord $model + * @return ActiveRecord */ - public function getWith($model): mixed + public function getWith(ActiveRecord $model): ActiveRecord { if (empty($this->with) || !is_array($this->with)) { return $model; diff --git a/Database/Base/BaseActiveRecord.php b/Database/Base/BaseActiveRecord.php index 4054fd4d..8e0c4bb2 100644 --- a/Database/Base/BaseActiveRecord.php +++ b/Database/Base/BaseActiveRecord.php @@ -11,7 +11,6 @@ namespace Database\Base; use Annotation\Event; -use Annotation\IAnnotation; use Annotation\Inject; use Annotation\Model\Get; use Annotation\Model\Set; @@ -55,6 +54,9 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess protected ?SEvent $event; + protected array $_with = []; + + /** @var array */ protected array $_attributes = []; @@ -658,6 +660,17 @@ abstract class BaseActiveRecord extends Component implements IOrm, ArrayAccess $this->_relate[$name] = $value; } + + /** + * @param $name + * @return bool + */ + public function hasRelate($name): bool + { + return isset($this->_relate[$name]); + } + + /** * @param array $relates */