@@ -174,7 +174,7 @@ public function setTable(string $table)
174
174
}
175
175
176
176
/**
177
- * Fetches the row of database from $this->table with a primary key
177
+ * Fetches the row(s) of database from $this->table with a primary key
178
178
* matching $id.
179
179
* This method works only with dbCalls.
180
180
*
@@ -198,25 +198,44 @@ protected function doFind(bool $singleton, $id = null)
198
198
$ builder ->where ($ this ->table . '. ' . $ this ->deletedField , null );
199
199
}
200
200
201
+ $ row = null ;
202
+ $ rows = [];
203
+
201
204
if (is_array ($ id )) {
202
- $ row = $ builder ->whereIn ($ this ->table . '. ' . $ this ->primaryKey , $ id )
205
+ $ rows = $ builder ->whereIn ($ this ->table . '. ' . $ this ->primaryKey , $ id )
203
206
->get ()
204
207
->getResult ($ this ->tempReturnType );
205
208
} elseif ($ singleton ) {
206
209
$ row = $ builder ->where ($ this ->table . '. ' . $ this ->primaryKey , $ id )
207
210
->get ()
208
211
->getFirstRow ($ this ->tempReturnType );
209
212
} else {
210
- $ row = $ builder ->get ()->getResult ($ this ->tempReturnType );
213
+ $ rows = $ builder ->get ()->getResult ($ this ->tempReturnType );
211
214
}
212
215
213
- if ($ useCast && $ row !== null ) {
214
- $ row = $ this ->convertToReturnType ($ row , $ returnType );
215
-
216
+ if ($ useCast ) {
216
217
$ this ->tempReturnType = $ returnType ;
218
+
219
+ if ($ singleton ) {
220
+ if ($ row === null ) {
221
+ return null ;
222
+ }
223
+
224
+ return $ this ->convertToReturnType ($ row , $ returnType );
225
+ }
226
+
227
+ foreach ($ rows as $ i => $ row ) {
228
+ $ rows [$ i ] = $ this ->convertToReturnType ($ row , $ returnType );
229
+ }
230
+
231
+ return $ rows ;
217
232
}
218
233
219
- return $ row ;
234
+ if ($ singleton ) {
235
+ return $ row ;
236
+ }
237
+
238
+ return $ rows ;
220
239
}
221
240
222
241
/**
@@ -230,15 +249,7 @@ protected function doFind(bool $singleton, $id = null)
230
249
*/
231
250
protected function doFindColumn (string $ columnName )
232
251
{
233
- $ results = $ this ->select ($ columnName )->asArray ()->find ();
234
-
235
- if ($ this ->useCasts ()) {
236
- foreach ($ results as $ i => $ row ) {
237
- $ results [$ i ] = $ this ->converter ->fromDataSource ($ row );
238
- }
239
- }
240
-
241
- return $ results ;
252
+ return $ this ->select ($ columnName )->asArray ()->find ();
242
253
}
243
254
244
255
/**
0 commit comments