Skip to content

Commit

Permalink
修复where值为空不处理的问题,修复dict和pairs问题
Browse files Browse the repository at this point in the history
  • Loading branch information
lhs168 committed Dec 21, 2017
1 parent 22de9f7 commit 18cc066
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/Fasim/Core/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ public static function query() {
}

public static function where($data = array(), $more=null) {
if ($more != null) {
if (is_string($data) && $more !== null) {
$data = [$data => $more];
}
//var_dump($data);
Expand Down
28 changes: 13 additions & 15 deletions src/Fasim/Db/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,19 @@ public function scalar($field) {
/**
* 根据指定的字段,从查询结果中取得一个pair关联数组
*
* @param string $key_field 用作数组key的字段
* @param string $value_field 用作value的字段
* @param string $keyField 用作数组key的字段
* @param string $valueField 用作value的字段
* @return array
*/
//???
public function pairs($key_field, $value_field) {
public function pairs($keyField, $valueField) {
$result = $this->find();
$ret = array();
foreach ($result as $row) {
if ($key_field == null || !isset($row[$key_field])) {
$ret[] = $row[$value_field];
foreach ($result as $item) {
if ($keyField == null || !isset($item->$valueField)) {
$ret[] = $item->$valueField;
} else {
$key = $row[$key_field];
$val = $row[$value_field];
$key = $item->$keyField;
$val = $item->$valueField;
$ret[$key] = $val;
}

Expand All @@ -120,16 +119,15 @@ public function pairs($key_field, $value_field) {
/**
* 获取全部数据,结果是以数据行中指定的字段为key的关联数组
*
* @param string $key 作为key的字段
* @param string $keyField 作为key的字段
* @return array
*/
//???
public function dict($key_field) {
public function dict($keyField) {
$result = $this->find();
$ret = array();
foreach ($result as $row) {
$key = $row[$key_field];
$ret[$key] = $row;
foreach ($result as $item) {
$key = $item->$keyField;
$ret[$key] = $item;
}
return $ret;
}
Expand Down

0 comments on commit 18cc066

Please sign in to comment.