次の Active Record クエリがあります。
//Example 1
public function info($school, $class, $student, $keyword)
{
$this->db->where('school.id', $school);
$this->db->where('class.id', $class);
$this->db->where('student.id', $student);
$this->db->or_where('school.description', $keyword);
$this->db->or_where('class.description', $keyword);
$this->db->or_where('student.description', $keyword);
return $this->db->get('info')->result();
}
下位 3 つの「or_where」ステートメントをグループ化して、上位 3 つの「where」ステートメントに含めたいと考えています。私が思いついた解決策はこれでした...
//Example 2
public function info($school, $class, $student, $keyword)
{
$this->db->where('school.description', $keyword);
$this->db->where('school.id', $school);
$this->db->where('class.id', $class);
$this->db->where('student.id', $student);
$this->db->or_where('class.description', $keyword);
$this->db->where('school.id', $school);
$this->db->where('class.id', $class);
$this->db->where('student.id', $student);
$this->db->or_where('student.description', $keyword);
$this->db->where('school.id', $school);
$this->db->where('class.id', $class);
$this->db->where('student.id', $student);
return $this->db->get('info')->result();
}
これは問題なく動作しますが、コードを繰り返さずにこれを行う方法はありますか?