@@ -230,7 +230,7 @@ public function insert () {
230
230
return false ;
231
231
232
232
$ id = $ this ->db ->insert ($ this ->dbTable , $ sqlData );
233
- if (!empty ($ this ->primaryKey ))
233
+ if (!empty ($ this ->primaryKey ) && ! isset ( $ this -> data [ $ this -> primaryKey ]) )
234
234
$ this ->data [$ this ->primaryKey ] = $ id ;
235
235
$ this ->isNew = false ;
236
236
@@ -269,13 +269,9 @@ public function update ($data = null) {
269
269
* @return mixed insert id or false in case of failure
270
270
*/
271
271
public function save ($ data = null ) {
272
- if ($ this ->isNew ) {
273
- $ id = $ this ->insert ();
274
- if (isset ($ this ->primaryKey ))
275
- $ this ->data [$ this ->primaryKey ] = $ id ;
276
- return $ id ;
277
- }
278
- return $ this ->update ($ data );
272
+ if ($ this ->isNew )
273
+ return $ this ->insert ();
274
+ return $ this ->update ($ data );
279
275
}
280
276
281
277
/**
@@ -316,6 +312,9 @@ private function byId ($id, $fields = null) {
316
312
private function getOne ($ fields = null ) {
317
313
$ this ->processHasOneWith ();
318
314
$ results = $ this ->db ->ArrayBuilder ()->getOne ($ this ->dbTable , $ fields );
315
+ if ($ this ->db ->count == 0 )
316
+ return null ;
317
+
319
318
$ this ->processArrays ($ results );
320
319
$ this ->data = $ results ;
321
320
$ this ->processAllWith ($ results );
@@ -344,6 +343,9 @@ private function get ($limit = null, $fields = null) {
344
343
$ objects = Array ();
345
344
$ this ->processHasOneWith ();
346
345
$ results = $ this ->db ->ArrayBuilder ()->get ($ this ->dbTable , $ limit , $ fields );
346
+ if ($ this ->db ->count == 0 )
347
+ return null ;
348
+
347
349
foreach ($ results as &$ r ) {
348
350
$ this ->processArrays ($ r );
349
351
$ this ->data = $ r ;
@@ -557,15 +559,15 @@ private function processHasOneWith () {
557
559
* @param array $data
558
560
*/
559
561
private function processArrays (&$ data ) {
560
- if (isset ($ this ->jsonFields ) && is_array ($ this ->jsonFields )) {
561
- foreach ($ this ->jsonFields as $ key )
562
- $ data [$ key ] = json_decode ($ data [$ key ]);
563
- }
562
+ if (isset ($ this ->jsonFields ) && is_array ($ this ->jsonFields )) {
563
+ foreach ($ this ->jsonFields as $ key )
564
+ $ data [$ key ] = json_decode ($ data [$ key ]);
565
+ }
564
566
565
- if (isset ($ this ->arrayFields ) && is_array ($ this ->arrayFields )) {
566
- foreach ($ this ->arrayFields as $ key )
567
- $ data [$ key ] = explode ("| " , $ data [$ key ]);
568
- }
567
+ if (isset ($ this ->arrayFields ) && is_array ($ this ->arrayFields )) {
568
+ foreach ($ this ->arrayFields as $ key )
569
+ $ data [$ key ] = explode ("| " , $ data [$ key ]);
570
+ }
569
571
}
570
572
571
573
/**
0 commit comments