Skip to content

Commit 994173b

Browse files
committed
added distinct, fixed: some issues
1 parent a78a232 commit 994173b

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Queriable.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,8 @@ protected function prepareResult($data)
315315
}
316316
} elseif (is_array($data) && count($data) != 0) {
317317
// $value = json_decode(json_encode($this->takeColumn($data)), true);
318-
$output = $this->instanceWithValue($data, ['_select' => $this->_select, '_except' => $this->_except]);
318+
//$output = $this->instanceWithValue($data, ['_select' => $this->_select, '_except' => $this->_except]);
319+
$output = $this->takeColumn($data);
319320
} else {
320321
$output = $data;
321322
}

src/QueryEngine.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,31 @@ public function countGroupBy($column)
409409
return $this;
410410
}
411411

412+
413+
/**
414+
* getting distinct data from specific column
415+
*
416+
* @param string $column
417+
* @return $this
418+
* @throws ConditionNotAllowedException
419+
*/
420+
public function distinct($column)
421+
{
422+
$this->prepare();
423+
424+
$data = [];
425+
foreach ($this->_map as $map) {
426+
$value = $this->getFromNested($map, $column);
427+
if ($value && !array_key_exists($value, $data)) {
428+
$data[$value] = $map;
429+
}
430+
}
431+
432+
$this->_map = array_values($data);
433+
return $this;
434+
}
435+
436+
412437
/**
413438
* count prepared data
414439
*

0 commit comments

Comments
 (0)