Laravel Eager加载无法作为数据库查询正常工作

时间:2018-12-06 14:38:27

标签: laravel eloquent

我正在使用2个雄辩的函数(supplierdemander)来调用我的事务,我正在记录查询,但是由于某种原因,它被完全错误地处理了。

 $transactionSegregated = Transaction::with([
            'demandCurrency',
            'supplier' => function($query){$query->where('is_test','=', 0);},
            'demander' => function($query){$query->where('is_test','=', 0);},
        ])
            ->where('date', '>=', $carbonDates['dateFrom'])
            ->where('date', '<=', $carbonDates['dateTo'])
            ->get();

供应商(和需求者)只是对客户的雄辩加入:

public function supplier(){
    return $this->belongsTo('App\Customer', 'site_user1');
}

这是我简单查询的相关部分,所有内容看起来都是100%。目前正在测试中,因此我将客户ID 21设置为is_test = 1,并且即使我要求他仅将其限制为is_test = 0的客户,它仍会显示该行:

 array (
    'query' => 'select * from `currencies` where `currencies`.`id` in (?)',
    'bindings' =>
    array (
      0 => 27,
    ),
    'time' => 2.1800000000000002,
  ),
  2 =>
  array (
    'query' => 'select * from `customers` where `customers`.`id` in (?) and `is_test` = ?',
    'bindings' =>
    array (
      0 => 21,
      1 => 0,
    ),
    'time' => 2.5299999999999998,
  ),
  3 =>
  array (
    'query' => 'select * from `customers` where `customers`.`id` in (?) and `is_test` = ?',
    'bindings' =>
    array (
      0 => 21,
      1 => 0,
    ),
    'time' => 2.5699999999999998,
  ),
  4 =>
  array (
    'query' => 'select * from `requests` where `approved_at` >= ? and `approved_at` <= ? and `request_status` = ?',
    'bindings' =>
    array (
      0 =>
      Illuminate\Support\Carbon::__set_state(array(
         'date' => '2018-12-06 00:00:00.774876',
         'timezone_type' => 3,
         'timezone' => 'America/Dominica',
      )),
      1 =>
      Illuminate\Support\Carbon::__set_state(array(
         'date' => '2018-12-06 10:32:36.774951',
         'timezone_type' => 3,
         'timezone' => 'America/Dominica',
      )),
      2 => 2,
    ),
    'time' => 2.7200000000000002,
  ),

我希望当demandersupplier的{​​{1}}时该行不返回

0 个答案:

没有答案