From 2802df28960dcde2a86a78a154cdcb6590152856 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Mon, 19 Dec 2016 13:33:38 +0100 Subject: [PATCH] fix insertorupdate method to work with newly created objects Change-Id: Ie7553e25855ec059f0ea366e86994ac7aa815ce2 --- phpbase/table.php | 10 +++++++++- 1 files changed, 9 insertions(+), 1 deletions(-) diff --git a/phpbase/table.php b/phpbase/table.php index 2e2f32a..de8fb47 100644 --- a/phpbase/table.php +++ b/phpbase/table.php @@ -216,8 +216,16 @@ abstract class WobTable /**updates existing object in the database or inserts it if it does not exist in the DB yet*/ public function insertOrUpdate() { + global $db; if($this->isfromdb)return $this->update(); - else return $this->insert(); + else { + if(count($db->select($this->table,"*",$this->where()))>0){ + $this->isfromdb=true; + $this->cdata=$this->data; + return $this->update(); + }else + return $this->insert(); + } } /**deletes this instance from the database; returns true if it actually executed*/ -- 1.7.2.5