framework
framework copied to clipboard
关于hasManyThrough的问题
首先,我的配置文件
// 数据库表前缀
'prefix' => 'd88_',
在使用hasManyThrough
的过程中
return $this->hasManyThrough(Role::class, ModelHasRole::class, 'user_id', 'id', $this->pk);
....
class ModelHasRole extends BaseModel
{
public $pk = 'role_id';
protected $table = 'model_has_role';
....
ModelHasRole
中定义了table, 但是得到的结果为 ** d88_model_has_role
**
我追溯了源码到, Query.php -> 851 行 -> getJoinTable() 中的 932 行, 发现传入的 $join
会被
if ($prefix && false === strpos($table, '.')
&& 0 !== strpos($table, $prefix)
&& 0 !== strpos($table, '__'))
{
$table = $this->getTable($table);
}
这一行代码改变, 从而结果变成了 d88_model_has_role
设置的$table 基本是失效了