
sections.id = 4 && companys.master_id = 1のレコードが存在するのかチェックする例を示します。
SQL
select exists(
select *
from `sections`
inner join `contents` on `contents`.`id` = `sections`.`content_id`
inner join `partys` on `partys`.`id` = `contents`.`party_id`
inner join `companys` on `companys`.`id` = `partys`.`company_id`
where `sections`.`id` = 4 and `companys`.`master_id` = 1) as `exists`;
Laravel
public function checkMasterExistsBySectionId($section_id, $master_id)
{
return $this->resource
->join('contents', 'contents.id', '=', 'sections.content_id')
->join('partys', 'partys.id', '=', 'contents.party_id')
->join('companys', 'companys.id', '=', 'partys.company_id')
->where('sections.id', $section_id)
->where('companys.master_id', $master_id)
->exists();
}

