Skip to content

Commit b072103

Browse files
committed
Merge pull request #259 from avbdr/master
fixes
2 parents 574943c + 199cdbb commit b072103

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

dbObject.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ public function __get ($name) {
141141
case 'hasone':
142142
$obj = new $modelName;
143143
$obj->returnType = $this->returnType;
144-
return $obj->byId($this->data[$name]);
144+
$this->data[$name] = $obj->byId($this->data[$name]);
145+
return $this->data[$name];
145146
break;
146147
case 'hasmany':
147148
$key = $this->relations[$name][2];
148149
$obj = new $modelName;
149150
$obj->returnType = $this->returnType;
150-
return $obj->where($key, $this->data[$this->primaryKey])->get();
151+
$this->data[$name] = $obj->where($key, $this->data[$this->primaryKey])->get();
152+
return $this->data[$name];
151153
break;
152154
default:
153155
break;
@@ -268,8 +270,12 @@ public function update ($data = null) {
268270
* @return mixed insert id or false in case of failure
269271
*/
270272
public function save ($data = null) {
271-
if ($this->isNew)
272-
return $this->insert();
273+
if ($this->isNew) {
274+
$id = $this->insert();
275+
if (isset ($this->primaryKey))
276+
$this->data[$this->primaryKey] = $id;
277+
return $id;
278+
}
273279
return $this->update($data);
274280
}
275281

0 commit comments

Comments
 (0)