From bbd6d4620eb8c1b20ace56eaa0b59106abf2e0d3 Mon Sep 17 00:00:00 2001
From: xamgore <xamgore@ya.ru>
Date: Sun, 5 Jul 2015 23:59:36 +0300
Subject: [PATCH] New function for grouping elements by unique key

This func have the same behaviour as `as_array` function, but the last one make array of [keys => arrays].

`groupByUniqueKey` just an array of [unique key => array].
---
 .../database/classes/Kohana/Database/Result.php      | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/~dev_rating/modules/database/classes/Kohana/Database/Result.php b/~dev_rating/modules/database/classes/Kohana/Database/Result.php
index f415891bd..b371c36fb 100644
--- a/~dev_rating/modules/database/classes/Kohana/Database/Result.php
+++ b/~dev_rating/modules/database/classes/Kohana/Database/Result.php
@@ -171,6 +171,18 @@ abstract class Kohana_Database_Result implements Countable, Iterator, SeekableIt
 		return $results;
 	}
 
+    public function groupByUniqueKey($key) {
+        $results = [];
+
+        foreach ($this as $row) {
+            $results[$row[$key]] = $row;
+        }
+
+        $this->rewind();
+
+        return $results;
+    }
+
 	/**
 	 * Return the named column from the current row.
 	 *
-- 
GitLab