Commit 93cd9d13 authored by Alexander Butenko's avatar Alexander Butenko

Merge pull request #274 from avbdr/master

Code cleanup
parents 25bf2fe6 5f89176a
...@@ -230,7 +230,7 @@ class dbObject { ...@@ -230,7 +230,7 @@ class dbObject {
return false; return false;
$id = $this->db->insert ($this->dbTable, $sqlData); $id = $this->db->insert ($this->dbTable, $sqlData);
if (!empty ($this->primaryKey)) if (!empty ($this->primaryKey) && !isset($this->data[$this->primaryKey]))
$this->data[$this->primaryKey] = $id; $this->data[$this->primaryKey] = $id;
$this->isNew = false; $this->isNew = false;
...@@ -269,13 +269,9 @@ class dbObject { ...@@ -269,13 +269,9 @@ class dbObject {
* @return mixed insert id or false in case of failure * @return mixed insert id or false in case of failure
*/ */
public function save ($data = null) { public function save ($data = null) {
if ($this->isNew) { if ($this->isNew)
$id = $this->insert(); return $this->insert();
if (isset ($this->primaryKey)) return $this->update ($data);
$this->data[$this->primaryKey] = $id;
return $id;
}
return $this->update($data);
} }
/** /**
...@@ -316,6 +312,9 @@ class dbObject { ...@@ -316,6 +312,9 @@ class dbObject {
private function getOne ($fields = null) { private function getOne ($fields = null) {
$this->processHasOneWith (); $this->processHasOneWith ();
$results = $this->db->ArrayBuilder()->getOne ($this->dbTable, $fields); $results = $this->db->ArrayBuilder()->getOne ($this->dbTable, $fields);
if ($this->db->count == 0)
return null;
$this->processArrays ($results); $this->processArrays ($results);
$this->data = $results; $this->data = $results;
$this->processAllWith ($results); $this->processAllWith ($results);
...@@ -344,6 +343,9 @@ class dbObject { ...@@ -344,6 +343,9 @@ class dbObject {
$objects = Array (); $objects = Array ();
$this->processHasOneWith (); $this->processHasOneWith ();
$results = $this->db->ArrayBuilder()->get ($this->dbTable, $limit, $fields); $results = $this->db->ArrayBuilder()->get ($this->dbTable, $limit, $fields);
if ($this->db->count == 0)
return null;
foreach ($results as &$r) { foreach ($results as &$r) {
$this->processArrays ($r); $this->processArrays ($r);
$this->data = $r; $this->data = $r;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment