@@ -51,20 +51,17 @@ public function find($id, $columns = array('*'))
5151 }
5252
5353 /**
54- * Execute the query as a "select" statement.
54+ * Execute the query as a fresh "select" statement.
5555 *
5656 * @param array $columns
57- * @return array
57+ * @return array|static[]
5858 */
59- public function get ($ columns = array ('* ' ))
59+ public function getFresh ($ columns = array ('* ' ))
6060 {
6161 // If no columns have been specified for the select statement, we will set them
6262 // here to either the passed columns, or the standard default of retrieving
6363 // all of the columns on the table using the "wildcard" column character.
64- if (is_null ($ this ->columns ))
65- {
66- $ this ->columns = $ columns ;
67- }
64+ if (is_null ($ this ->columns )) $ this ->columns = $ columns ;
6865
6966 // Drop all columns if * is present
7067 if (in_array ('* ' , $ this ->columns ))
@@ -160,6 +157,27 @@ public function get($columns = array('*'))
160157 }
161158 }
162159
160+ /**
161+ * Generate the unique cache key for the query.
162+ *
163+ * @return string
164+ */
165+ public function generateCacheKey ()
166+ {
167+ $ key = array (
168+ 'connection ' => $ this ->connection ->getName (),
169+ 'collection ' => $ this ->collection ->getName (),
170+ 'wheres ' => $ this ->wheres ,
171+ 'columns ' => $ this ->columns ,
172+ 'groups ' => $ this ->groups ,
173+ 'orders ' => $ this ->orders ,
174+ 'offset ' => $ this ->offset ,
175+ 'aggregate ' => $ this ->aggregate ,
176+ );
177+
178+ return md5 (serialize (array_values ($ key )));
179+ }
180+
163181 /**
164182 * Execute an aggregate function on the database.
165183 *
@@ -173,6 +191,11 @@ public function aggregate($function, $columns = array('*'))
173191
174192 $ results = $ this ->get ($ columns );
175193
194+ // Once we have executed the query, we will reset the aggregate property so
195+ // that more select queries can be executed against the database without
196+ // the aggregate value getting in the way when the grammar builds it.
197+ $ this ->columns = null ; $ this ->aggregate = null ;
198+
176199 if (isset ($ results [0 ]))
177200 {
178201 return $ results [0 ][$ columns [0 ]];
@@ -343,7 +366,7 @@ public function decrement($column, $amount = 1, array $extra = array())
343366 */
344367 public function delete ($ id = null )
345368 {
346- $ query = $ this ->compileWheres ($ this );
369+ $ query = $ this ->compileWheres ();
347370 $ result = $ this ->collection ->remove ($ query );
348371
349372 if (1 == (int ) $ result ['ok ' ])
0 commit comments