<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet href="https://dev.horde.org/themes/horde//default/feed-rss.xsl" type="text/xsl"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
 <channel> 
  <title>Rdo Mapper update function cannot create new records from Horde_Rdo_Base objects</title> 
  <pubDate>Fri, 10 Apr 2026 20:05:42 +0000</pubDate> 
  <link>https://bugs.horde.org/ticket/8225</link> 
  <atom:link rel="self" type="application/rss+xml" title="Rdo Mapper update function cannot create new records from Horde_Rdo_Base objects" href="https://bugs.horde.org/ticket/8225/rss" /> 
  <description>Rdo Mapper update function cannot create new records from Horde_Rdo_Base objects</description> 
 
   
   
  <item> 
   <title>PROBLEM



The Horde_Rdo_Mapper::update tries to create new </title> 
   <description>PROBLEM



The Horde_Rdo_Mapper::update tries to create new records from Horde_Rdo_Base objects, assigning a null value for the primary key.



Example:



class MyTable extends Horde_Rdo_Base ...



$row = new MyTable(array(some values here));

$row-&gt;save();  // calls the mapper update function



Fatal error: Uncaught exception &#039;Horde_Rdo_Exception&#039; with message &#039;Column &#039;mytable_id&#039; cannot be null...



This is happening with a fairly default Apache/PHP installation on a MacBook using MySQL.



PATCH



Suggest modifying the Horde_Rdo_Mapper::update function to unset the primary key before calling create on the array. The key has already been proven empty by the if statement, so I can&#039;t imagine any negative effect here.



    public function update($object, $fields = null)

    {

        if ($object instanceof Horde_Rdo_Base) {

            $key = $this-&gt;model-&gt;key;

            $id = $object-&gt;$key;

            $fields = iterator_to_array($object);



            if (!$id) {

                // Object doesn&#039;t exist yet; create it instead.

                unset($fields[$key]);

                $object = $this-&gt;create($fields);

                return 1;

            }



SIDENOTE



The CVS repository for Rdo seems to be missing or just not showing files:



http://cvs.horde.org/framework/Rdo/Rdo/



Also, </description> 
   <pubDate>Tue, 28 Apr 2009 03:21:32 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8225#t53896</link> 
  </item> 
   
  <item> 
   <title>No also. Forgot to erase it. Thank you.</title> 
   <description>No also. Forgot to erase it. Thank you.</description> 
   <pubDate>Tue, 28 Apr 2009 03:24:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8225#t53897</link> 
  </item> 
   
  <item> 
   <title>After poking around with this a bit more, I&#039;ve realized that</title> 
   <description>After poking around with this a bit more, I&#039;ve realized that This only happens for MySQL tables that have not set their primary key field to auto_increment.  I&#039;m still not convinced it&#039;s best form to dump an empty primary key down an insert statement, but MySQL does handle this gracefully when the table is an auto_increment table. I have not tested this on other database server types. Here is example SQL generated by Horde_Rdo_Adapter::create.



INSERT INTO `mytable` (`mytable_id`, `user_uid`, `title`, `description`, `created`, `updated`) VALUES (?, ?, ?, ?, ?, ?)



Values Array ( [0] =&gt; [1] =&gt; admin [2] =&gt; actually [3] =&gt; do it [4] =&gt; 1240893214 [5] =&gt; 1240893214 ) </description> 
   <pubDate>Tue, 28 Apr 2009 04:42:37 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8225#t53900</link> 
  </item> 
   
  <item> 
   <title>Are you really still using FRAMEWORK_3 of Rdo? That code was</title> 
   <description>Are you really still using FRAMEWORK_3 of Rdo? That code was only a showcase for upcoming features, the latest is in Git.</description> 
   <pubDate>Tue, 28 Apr 2009 07:28:21 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/8225#t53903</link> 
  </item> 
   
   
 
 </channel> 
</rss> 
