File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 4040
4141use CodeIgniter \Database \BaseResult ;
4242use CodeIgniter \Database \ResultInterface ;
43+ use CodeIgniter \Entity ;
4344
4445/**
4546 * Result for MySQLi
@@ -156,10 +157,15 @@ protected function fetchAssoc()
156157 *
157158 * @param string $className
158159 *
159- * @return object
160+ * @return object|boolean|Entity
160161 */
161162 protected function fetchObject (string $ className = 'stdClass ' )
162163 {
164+ if (is_subclass_of ($ className , Entity::class))
165+ {
166+ $ data = $ this ->fetchAssoc ();
167+ return empty ($ data ) ? false : (new $ className ())->setRawArray ($ data );
168+ }
163169 return $ this ->resultID ->fetch_object ($ className );
164170 }
165171
Original file line number Diff line number Diff line change 4040
4141use CodeIgniter \Database \BaseResult ;
4242use CodeIgniter \Database \ResultInterface ;
43+ use CodeIgniter \Entity ;
4344
4445/**
4546 * Result for Postgre
@@ -154,10 +155,15 @@ protected function fetchAssoc()
154155 *
155156 * @param string $className
156157 *
157- * @return object
158+ * @return object|boolean|Entity
158159 */
159160 protected function fetchObject (string $ className = 'stdClass ' )
160161 {
162+ if (is_subclass_of ($ className , Entity::class))
163+ {
164+ $ data = $ this ->fetchAssoc ();
165+ return empty ($ data ) ? false : (new $ className ())->setRawArray ($ data );
166+ }
161167 return pg_fetch_object ($ this ->resultID , null , $ className );
162168 }
163169
Original file line number Diff line number Diff line change 4040use CodeIgniter \Database \BaseResult ;
4141use CodeIgniter \Database \Exceptions \DatabaseException ;
4242use CodeIgniter \Database \ResultInterface ;
43+ use CodeIgniter \Entity ;
4344
4445/**
4546 * Result for SQLite3
@@ -182,6 +183,12 @@ protected function fetchObject(string $className = 'stdClass')
182183 }
183184
184185 $ classObj = new $ className ();
186+
187+ if (is_subclass_of ($ className , Entity::class))
188+ {
189+ return $ classObj ->setRawArray ($ row );
190+ }
191+
185192 $ classSet = \Closure::bind (function ($ key , $ value ) {
186193 $ this ->$ key = $ value ;
187194 }, $ classObj , $ className
Original file line number Diff line number Diff line change @@ -238,7 +238,7 @@ public function syncOriginal()
238238 * Checks a property to see if it has changed since the entity was created.
239239 * Or, without a parameter, checks if any properties have changed.
240240 *
241- * @param ? string $key
241+ * @param string $key
242242 *
243243 * @return boolean
244244 */
@@ -247,9 +247,9 @@ public function hasChanged(string $key = null): bool
247247 // If no parameter was given then check all attributes
248248 if ($ key === null )
249249 {
250- return $ this ->original !== $ this ->attributes ;
250+ return $ this ->original !== $ this ->attributes ;
251251 }
252-
252+
253253 // Key doesn't exist in either
254254 if (! array_key_exists ($ key , $ this ->original ) && ! array_key_exists ($ key , $ this ->attributes ))
255255 {
@@ -427,6 +427,19 @@ public function __isset(string $key): bool
427427 return isset ($ this ->attributes [$ key ]);
428428 }
429429
430+ /**
431+ * Set raw data array without any mutations
432+ *
433+ * @param array $data
434+ * @return $this
435+ */
436+ public function setRawArray (array $ data )
437+ {
438+ $ this ->attributes = $ data ;
439+ $ this ->syncOriginal ();
440+ return $ this ;
441+ }
442+
430443 //--------------------------------------------------------------------
431444
432445 /**
You can’t perform that action at this time.
0 commit comments