Revert "Return the new primary id if creating objects. We should really manipulate...
authorChuck Hagenbuch <chuck@horde.org>
Wed, 2 Sep 2009 04:24:45 +0000 (00:24 -0400)
committerChuck Hagenbuch <chuck@horde.org>
Wed, 2 Sep 2009 04:24:45 +0000 (00:24 -0400)
This reverts commit 9ffa9a348780347ae0bb0b69abfffa699cff5702.

framework/Rdo/lib/Horde/Rdo/Base.php
framework/Rdo/lib/Horde/Rdo/Mapper.php

index 1b3a19a..be8bfc6 100644 (file)
@@ -250,14 +250,13 @@ abstract class Horde_Rdo_Base implements IteratorAggregate {
     }
 
     /**
-     * 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;
     }
 
     /**
index 5a26980..887594d 100644 (file)
@@ -356,33 +356,33 @@ abstract class Horde_Rdo_Mapper implements Countable
 
         $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;
@@ -410,7 +410,7 @@ abstract class Horde_Rdo_Mapper implements Countable
         $sql = substr($sql, 0, -1) . ' WHERE ' . $this->primaryKey . ' = ?';
         $bindParams[] = $id;
 
-        return (bool)$this->adapter->update($sql, $bindParams);
+        return $this->adapter->update($sql, $bindParams);
     }
 
     /**