LaravelのJoinをクロージャで使った時に「Invalid text representation: 7 ERROR」が出た時
$query = $this ->from('tbl_reservation as tr') ->join('tbl_course as tc','tr.f_course_id', '=', 'tc.f_course_id') ->join('tbl_slot_course as tsc', function ($join) { $join ->on('tsc.f_reservation_slot_id', '=', 'trs.f_reservation_slot_id') ->where('tsc.f_course_id', '=', 'tc.f_course_id'); })
↑は「f_course_id」の部分で「Invalid text representation: 7 ERROR: invalid input syntax for integer」が出る
あ、whereの指定かな?と思って「where('tsc.f_course_id', 'tc.f_course_id')」に変更
$query = $this ->from('tbl_reservation as tr') ->join('tbl_course as tc','tr.f_course_id', '=', 'tc.f_course_id') ->join('tbl_slot_course as tsc', function ($join) { $join ->on('tsc.f_reservation_slot_id', '=', 'trs.f_reservation_slot_id') ->where('tsc.f_course_id', 'tc.f_course_id'); })
↑も「Invalid text representation: 7 ERROR: invalid input syntax for integer」が出る
なので、whereColumnを使ってみると...
$query = $this ->from('tbl_reservation as tr') ->join('tbl_course as tc','tr.f_course_id', '=', 'tc.f_course_id') ->join('tbl_slot_course as tsc', function ($join) { $join ->on('tsc.f_reservation_slot_id', '=', 'trs.f_reservation_slot_id') ->whereColumn('tsc.f_course_id', 'tc.f_course_id'); })
いけた。
なんとなく理解した記事。
stackoverflow.com
joinのクロージャの引数$joinの型が「Illumintate\Database\Query\JoinClause」であるため、このような現象が起きたようです。
使えるメソッドが違うっぽいです。
色々あるのね。。。。。