标签:code prot HERE protected return fun logs names his
在一个模型中,新建方法实现外键关联
<?php namespace app\user\model; use think\Model; class GridmanReportLogs extends Model { protected $table = ‘sq_gridman_report_logs‘; protected $pk = ‘id‘; protected $resultSetType = ‘collection‘; public function reportTypeName() { return $this->hasOne(‘GridmanReportType‘, ‘id‘, ‘report_type_id‘)->bind(‘report_type‘); } public function user() { return $this->hasOne(‘Users‘, ‘id‘, ‘user_id‘)->bind(‘name‘); } }
通过with关联表使用该方法
$this->gridmanReportLogs->with(‘user‘, ‘LEFT‘)->where(‘user_id‘, $userId)->select();
标签:code prot HERE protected return fun logs names his
原文地址:https://www.cnblogs.com/YC-L/p/12640196.html