@@ -230,7 +230,7 @@ public function insert () {
230230 return false ;
231231
232232 $ id = $ this ->db ->insert ($ this ->dbTable , $ sqlData );
233- if (!empty ($ this ->primaryKey ))
233+ if (!empty ($ this ->primaryKey ) && ! isset ( $ this -> data [ $ this -> primaryKey ]) )
234234 $ this ->data [$ this ->primaryKey ] = $ id ;
235235 $ this ->isNew = false ;
236236
@@ -269,13 +269,9 @@ public function update ($data = null) {
269269 * @return mixed insert id or false in case of failure
270270 */
271271 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 );
279275 }
280276
281277 /**
@@ -316,6 +312,9 @@ private function byId ($id, $fields = null) {
316312 private function getOne ($ fields = null ) {
317313 $ this ->processHasOneWith ();
318314 $ results = $ this ->db ->ArrayBuilder ()->getOne ($ this ->dbTable , $ fields );
315+ if ($ this ->db ->count == 0 )
316+ return null ;
317+
319318 $ this ->processArrays ($ results );
320319 $ this ->data = $ results ;
321320 $ this ->processAllWith ($ results );
@@ -344,6 +343,9 @@ private function get ($limit = null, $fields = null) {
344343 $ objects = Array ();
345344 $ this ->processHasOneWith ();
346345 $ results = $ this ->db ->ArrayBuilder ()->get ($ this ->dbTable , $ limit , $ fields );
346+ if ($ this ->db ->count == 0 )
347+ return null ;
348+
347349 foreach ($ results as &$ r ) {
348350 $ this ->processArrays ($ r );
349351 $ this ->data = $ r ;
@@ -557,15 +559,15 @@ private function processHasOneWith () {
557559 * @param array $data
558560 */
559561 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+ }
564566
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+ }
569571 }
570572
571573 /**
0 commit comments