From 72c38e641d7d0a5cbeae1061e0435037a6301794 Mon Sep 17 00:00:00 2001 From: Alexander Demidov Date: Thu, 19 Sep 2013 12:54:10 +0400 Subject: [PATCH] Refactoring assoc use in SqlResultProvider. Write SqlCriteria.find() method. --- model/SqlCriteria.php | 13 ++++++++++++- model/SqlResultProvider.php | 8 +++----- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/model/SqlCriteria.php b/model/SqlCriteria.php index 695e776..0afbf8c 100644 --- a/model/SqlCriteria.php +++ b/model/SqlCriteria.php @@ -17,9 +17,20 @@ class SqlCriteria */ private $model; - public function find() + /** + * @param $model SqlModel + */ + public function __construct($model) { + $this->model = $model; + } + /** + * @return SqlResultProvider + */ + public function find() + { + return $this->model->find($this->select, $this->distinct, $this->where, $this->order, $this->limit); } /** diff --git a/model/SqlResultProvider.php b/model/SqlResultProvider.php index fa7f2b8..f8d3de9 100644 --- a/model/SqlResultProvider.php +++ b/model/SqlResultProvider.php @@ -17,7 +17,7 @@ class SqlResultProvider $this->result_items = $result_items; } - public function assoc($field, $assoc_as_array = false, $field_assoc_in_array = null) + public function assoc($field, $assoc_as_array = false) { if (is_null($this->result_items_base)) { $this->result_items_base = $this->result_items; @@ -40,11 +40,9 @@ class SqlResultProvider } } // Ассоциирование внутри каждого элемента массива - // $field_assoc_in_array - ассоциирование произовдится по этому полю (вернет ошибку, если этого поля нет в результатх выборки) - if ($assoc_as_array && $field_assoc_in_array) { + if ($assoc_as_array) { foreach ($result_items_assoc as &$value) { - $sql_result_provider = new SqlResultProvider($value); - $value = $sql_result_provider->assoc($field_assoc_in_array)->fetchAll(); + $value = new SqlResultProvider($value); } } $this->result_items = $result_items_assoc;