模型方法select和find的bug

浏览:545 发布日期:2016/06/27 分类:求助交流
所用版本 thinkphp 3.2.3
使用模型方法 select 和 find 时,参数如果传入 数字 或 字符串,将导致连贯操作where传入内容丢失。
例如 :
$map = array('status'=>1);
D('User')->where($map)->find(3);
其查询结果 仅仅是 SELECT * FROM `user` WHERE `id` = 3; status = 1 的条件均被忽略。
查看源码 ThinkPHP/Library/Think/Model.class.php 中的 find 方法第721~724行:
if(is_numeric($options) || is_string($options)) {
$where[$this->getPk()] = $options;
$options = array();
$options['where'] = $where;
}
options数组所有内容被丢弃,也包括where方法传入的内容。

同样的问题也出现在select方法的第540~548行:
if(is_string($options) || is_numeric($options)) {
// 根据主键查询
if(strpos($options,',')) {
$where[$pk] = array('IN',$options);
}else{
$where[$pk] = $options;
}
$options = array();
$options['where'] = $where;



最佳答案
评论( 相关
后面还有条评论,点击查看>>