最近,我再次注意到 CodeIgniter 的 ActiveRecord 库中存在一个令人难以置信的逻辑错误。
当我尝试在联接中使用“AND”时出现问题。
示例查询:
$this -> db -> join(
'predict',
"predict.id_predict = portion.id_predict AND event.id_event = 5",
'left'
);
结果:
LEFT JOIN `predict` ON
`predict`.`id_predict` = `portion`.`id_predict`
AND event.id_event = 5
但应该更有可能:
LEFT JOIN `predict` ON (
`predict`.`id_predict` = `portion`.`id_predict`
AND `event`.`id_event` = 5
)
有什么办法可以避免这种错误吗?
最佳答案
$this->db->join(
'predict',
"(predict.id_predict = portion.id_predict AND `event`.`id_event` = 5)",
'left'
);
你在找这个吗?
编辑
$this->db->join('predict', "predict.id_predict = portion.id_predict", 'left');
$this->db->where('event.id_event = 5');
关于mysql - Buggy 加入 CodeIgniter ActiveRecord,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696254/