Laravel 5.4哪里有查询bug

时间:2017-08-02 23:54:37

标签: mysql laravel laravel-5 eloquent

对于大多数代码有效的曲目,但对某些曲目不起作用。 我的代码出了什么问题?

$track = Track::where( 'id', 7 )->whereHas('rights', function ( $query ){
    $query->where( 'user_id',  1 );
})->get();
dd( $track );

输出

Collection {#301
  #items: []
}

SQL

select * from `tracks` where `id` = ? and exists (select * from `rights` where `tracks`.`id` = `rights`.`track_id` and `user_id` = ?) and `tracks`.`deleted_at` is null

数据库

rights
---
| id | rightholder_type_id | user_id | track_id |
| -: |          -:         |   -:    |     -    |
| 29 |           1         |    1    |     7    | 

0 个答案:

没有答案