smartweb 发表于 2011-4-9 07:19:41

activerecord的OR操作有严重问题,可能因我而升级了

我要达到如下效果
select * from table where id = '130' OR logics LIKE ('130')
我使用
$cid = 130;
$this->db->where('id',$cid);
$this->db->or_like('logics',$cid);
但出来的效果是:
select * from table where id = '130' AND logics LIKE ('130') <-- 注意这里的AND,并不是OR
我在Codeigniter官网发帖,有用户bhumes也测试过了,他有如下的解决
修改DB_active_rec.php (lines 1765-1775)
// Write the "LIKE" portion of the query

if (count($this->ar_like) > 0)
{
if (count($this->ar_where) > 0)
{
    $sql .= "\nAND ";
}

$sql .= implode("\n", $this->ar_like);
}

我觉得随便修改核心内容并不是很好的办法,看来 CI又要升级了,可能因我而升级了:lol

jeongee 发表于 2011-4-9 10:55:11

不是因你,是因写CI 的人,因他们的疏忽。

visvoy 发表于 2011-4-9 12:34:35

恩,这问题一直存在

Hex 发表于 2011-4-9 16:54:34

我觉得没必要纠结在 AR 上,用合适的方法做合适的事情。
query() 也挺好用的。

zhouli520 发表于 2011-4-11 11:14:31

简单的插入修改我都是ar
负责点的我就query+sql语句,这样随便ci怎么升级我也不用担心我model层出问题了.
至少最基础的update insert ci应该是不会有多大改变的.

smartweb 发表于 2011-4-12 20:55:51

折衷的解决方法:
$cid = 130;
$this->db->where(‘id’,$cid);
$this->db->or_where(‘logics LIKE’,”%,”.$cid.”,%”)

能不能加分呢?
页: [1]
查看完整版本: activerecord的OR操作有严重问题,可能因我而升级了