OrgModel模型(用户所属组织机构表)
<?php
namespace app\model;
use app\BaseModel;
use think\Model;
class OrgModel extends BaseModel
{
protected $name = 't_org';
protected $pk = 'org_id';
}
UserModel模型(用户表)
<?php
namespace app\model;
use app\BaseModel;
use think\Model;
class UserModel extends BaseModel
{
protected $name = 't_user';
protected $pk = 'user_id';
public function org()
{
return $this->hasOne(OrgModel::class, 'org_id', 'org_id');
}
}
查询
$model = UserModel::withJoin([
'org' => ['org_name']
], 'LEFT');
$model = $model->limit($offset, $limit);
return $model->select();