}
/**
- * Saves any changes to the backend.
+ * Save any changes to the backend.
*
- * @return boolean|integer Primary key if the object was created, whether
- * the updated succeeded otherwise.
+ * @return boolean Success.
*/
public function save()
{
- return $this->getMapper()->update($this);
+ return $this->getMapper()->update($this) == 1;
}
/**
$id = $this->adapter->insert($sql, $bindParams);
- return $this->map(array_merge($fields, array($this->primaryKey => $id)));
+ return $this->map(array_merge(array($this->primaryKey => $id),
+ $fields));
}
/**
- * Updates a record in the backend.
+ * Updates a record in the backend. $object can be either a
+ * primary key or an Rdo object. If $object is an Rdo instance
+ * then $fields will be ignored as values will be pulled from the
+ * object.
*
- * $object can be either a primary key or an Rdo object. If $object is an
- * Rdo instance then $fields will be ignored as values will be pulled from
- * the object.
+ * @param string|Rdo $object The Rdo instance or unique id to update.
+ * @param array $fields If passing a unique id, the array of field properties
+ * to set for $object.
*
- * @param string|Rdo $object The Rdo instance or unique id to update.
- * @param array $fields If passing a unique id, the array of field
- * properties to set for $object.
- *
- * @return boolean|integer Primary key if the object was created, whether
- * the updated succeeded otherwise.
+ * @return integer Number of objects updated.
*/
public function update($object, $fields = null)
{
if ($object instanceof Horde_Rdo_Base) {
- $id = $object->{$this->primaryKey};
+ $key = $this->primaryKey;
+ $id = $object->$key;
$fields = iterator_to_array($object);
if (!$id) {
// Object doesn't exist yet; create it instead.
$object = $this->create($fields);
- return $object->{$this->primaryKey};
+ return 1;
}
} else {
$id = $object;
$sql = substr($sql, 0, -1) . ' WHERE ' . $this->primaryKey . ' = ?';
$bindParams[] = $id;
- return (bool)$this->adapter->update($sql, $bindParams);
+ return $this->adapter->update($sql, $bindParams);
}
/**