Refactoring assoc use in SqlResultProvider. Write SqlCriteria.find() method.
This commit is contained in:
@ -17,9 +17,20 @@ class SqlCriteria
|
||||
*/
|
||||
private $model;
|
||||
|
||||
/**
|
||||
* @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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
|
Reference in New Issue
Block a user