[英]Codeigniter and doctrine join three tables
您好,我正在尝试在规范codeigniter中加入3个表,我已经成功地加入了两个表,但是在加入第三个表时遇到了问题。
这是我的codeigniter活动记录查询。 我想在学说中处理此查询
$query = $this->db->select('table1.name, table3.date')
->from('table1')
->join('table2', 'table2.id = table1.Uid')
->join('table3', 'table3.id = table1.Rid')
->where('table1.Uid', $Uid)
->get();
return $query->result();
这是我的主义查询生成器查询,在其中我成功地连接了两个表。
$qb = $this->em->createQueryBuilder();
$query = $qb->select('t1, t2')
->from('table1', 't1')
->join('table2', 't2')
// ->join('table3', 't3')
->where('t1.Uid = :Uid')
->andwhere('t2.Yid = :Yid')
->setParameters(array('Uid'=> $Uid, 'Yid' => $user_id))
->getQuery()
->getResult();
尝试使用以下代码,看来您的语法不正确。
$qb = $this->em->createQueryBuilder();
$query = $qb->select('t1.name', 't2.name')
->from('table1', 't1')
->leftJoin('t1', 'table2', 't2', 't2.id = t1.Uid')
->leftJoin('t1', 'table3', 't3', 't3.id = t1.Rid')
->where('t1.Uid = :Uid')
->andwhere('t2.Yid = :Yid')
->setParameters(array('Uid'=> $Uid, 'Yid' => $user_id))
->getQuery()
->getResult()
有关构造新的QueryBuilder对象的更多信息
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.