用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2946|回复: 5
收起左侧

[已解决] activerecord的OR操作有严重问题,可能因我而升级了

[复制链接]
发表于 2011-4-9 07:19:41 | 显示全部楼层 |阅读模式
我要达到如下效果
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又要升级了,可能因我而升级了
发表于 2011-4-9 10:55:11 | 显示全部楼层
不是因你,是因写CI 的人,因他们的疏忽。
发表于 2011-4-9 12:34:35 | 显示全部楼层
恩,这问题一直存在
发表于 2011-4-9 16:54:34 | 显示全部楼层
我觉得没必要纠结在 AR 上,用合适的方法做合适的事情。
query() 也挺好用的。
发表于 2011-4-11 11:14:31 | 显示全部楼层
简单的插入修改我都是ar
负责点的我就query+sql语句,这样随便ci怎么升级我也不用担心我model层出问题了.
至少最基础的update insert ci应该是不会有多大改变的.
 楼主| 发表于 2011-4-12 20:55:51 | 显示全部楼层
折衷的解决方法:
$cid = 130;
$this->db->where(‘id’,$cid);
$this->db->or_where(‘logics LIKE’,”%,”.$cid.”,%”)

  能不能加分呢?

本版积分规则