diff --git a/library/think/model/relation/OneToOne.php b/library/think/model/relation/OneToOne.php index 18b92225..c64dfcbb 100644 --- a/library/think/model/relation/OneToOne.php +++ b/library/think/model/relation/OneToOne.php @@ -67,6 +67,7 @@ abstract class OneToOne extends Relation $field = true; } $query->field($field, false, $table, $alias); + $field = null; } // 预载入封装 @@ -82,7 +83,7 @@ abstract class OneToOne extends Relation if ($closure) { // 执行闭包查询 - call_user_func_array($closure, [& $query]); + call_user_func_array($closure, [ & $query]); // 使用withField指定获取关联的字段,如 // $query->where(['id'=>1])->withField('id,name'); if ($query->getOptions('with_field')) { @@ -91,10 +92,8 @@ abstract class OneToOne extends Relation } } elseif (isset($this->option['field'])) { $field = $this->option['field']; - } else { - $field = true; } - $query->field($field, false, $joinTable, $joinAlias, $relation . '__'); + $query->field(isset($field) ? $field : true, false, $joinTable, $joinAlias, $relation . '__'); } /** @@ -290,7 +289,7 @@ abstract class OneToOne extends Relation { // 预载入关联查询 支持嵌套预载入 if ($closure) { - call_user_func_array($closure, [& $model]); + call_user_func_array($closure, [ & $model]); if ($field = $model->getOptions('with_field')) { $model->field($field)->removeOption('with_field'); }