File tree Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Expand file tree Collapse file tree 1 file changed +25
-7
lines changed Original file line number Diff line number Diff line change @@ -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,43 @@ protected function doFind(bool $singleton, $id = null)
198
198
$ builder ->where ($ this ->table . '. ' . $ this ->deletedField , null );
199
199
}
200
200
201
+ $ rows = [];
202
+
201
203
if (is_array ($ id )) {
202
- $ row = $ builder ->whereIn ($ this ->table . '. ' . $ this ->primaryKey , $ id )
204
+ $ rows = $ builder ->whereIn ($ this ->table . '. ' . $ this ->primaryKey , $ id )
203
205
->get ()
204
206
->getResult ($ this ->tempReturnType );
205
207
} elseif ($ singleton ) {
206
208
$ row = $ builder ->where ($ this ->table . '. ' . $ this ->primaryKey , $ id )
207
209
->get ()
208
210
->getFirstRow ($ this ->tempReturnType );
209
211
} else {
210
- $ row = $ builder ->get ()->getResult ($ this ->tempReturnType );
212
+ $ rows = $ builder ->get ()->getResult ($ this ->tempReturnType );
211
213
}
212
214
213
- if ($ useCast && $ row !== null ) {
214
- $ row = $ this ->convertToReturnType ($ row , $ returnType );
215
-
215
+ if ($ useCast ) {
216
216
$ this ->tempReturnType = $ returnType ;
217
+
218
+ if ($ singleton ) {
219
+ if ($ row === null ) {
220
+ return null ;
221
+ }
222
+
223
+ return $ this ->convertToReturnType ($ row , $ returnType );
224
+ }
225
+
226
+ foreach ($ rows as $ i => $ row ) {
227
+ $ rows [$ i ] = $ this ->convertToReturnType ($ row , $ returnType );
228
+ }
229
+
230
+ return $ rows ;
217
231
}
218
232
219
- return $ row ;
233
+ if ($ singleton ) {
234
+ return $ row ;
235
+ }
236
+
237
+ return $ rows ;
220
238
}
221
239
222
240
/**
You can’t perform that action at this time.
0 commit comments