新增模型自动关联功能

This commit is contained in:
JaguarJack
2021-05-31 08:43:29 +08:00
parent 9873a2156b
commit 44f5bf345b
2 changed files with 96 additions and 1 deletions

View File

@@ -6,6 +6,7 @@ namespace catcher\base;
use catcher\CatchQuery;
use catcher\traits\db\BaseOptionsTrait;
use catcher\traits\db\RewriteTrait;
use catcher\traits\db\WithTrait;
use think\model\concern\SoftDelete;
use catcher\traits\db\ScopeTrait;
@@ -17,7 +18,7 @@ use catcher\traits\db\ScopeTrait;
*/
abstract class CatchModel extends \think\Model
{
use SoftDelete, BaseOptionsTrait, ScopeTrait, RewriteTrait;
use SoftDelete, BaseOptionsTrait, ScopeTrait, RewriteTrait, WithTrait;
protected $createTime = 'created_at';
@@ -47,4 +48,14 @@ abstract class CatchModel extends \think\Model
{
return property_exists($this, 'field') && in_array($field, $this->field);
}
public function __construct(array $data = [])
{
parent::__construct($data);
if (method_exists($this, 'autoWithRelation')) {
$this->autoWithRelation();
}
}
}