相关疑难解决方法(0)

Laravel 4.1 Eloquent - 使用whereHas的自定义连接

我正在使用名为seven_ora的2个连接的MSSQL(用户模型的表位于其中)和sho(字符模型的表所在的连接).

用户拥有多个字符,而一个字符属于用户.

当我尝试:

Character::whereHas('User', function($q) { $q->where('gm', 1); });
Run Code Online (Sandbox Code Playgroud)

它似乎使用与Character相同的连接.似乎whereHas中的闭包是Query\Builder?我期望whereHas使用它所指的任何模型的相应集合连接.

有没有办法在我的whereHas闭包上使用不同的连接?

Characters.php(模型)

class Character extends Base {

    /**
     * Connection used by the model
     *
     * @var string
     */
    protected $connection = 'sho';

    /**
     * Table used by the model
     *
     * @var string
     */
    protected $table = 'tblgs_avatar';

    /**
     * Fields fillable by the model
     *
     * @var array
     */
    protected $guarded = array('*');

    /**
     * Checks whether the model uses timestamps
     *
     * @var boolean
     */
    public $timestamps …
Run Code Online (Sandbox Code Playgroud)

laravel eloquent

2
推荐指数
1
解决办法
1168
查看次数

标签 统计

eloquent ×1

laravel ×1