mercredi 2 août 2017

Laravel 5.4 whereHas query bug

For most tracks that code works, but for some it doesn't. What's wrong with my code?

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

Collection {#301
  #items: []
}

sql is - "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"

Database:

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



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire