6.0.0-alpha14
7/2/25

[#8225] Rdo Mapper update function cannot create new records from Horde_Rdo_Base objects
Summary Rdo Mapper update function cannot create new records from Horde_Rdo_Base objects
Queue Horde Framework Packages
Queue Version FRAMEWORK_3
Type Bug
State No Feedback
Priority 2. Medium
Owners
Requester tenorviol (at) yahoo (dot) com
Created 04/28/2009 (5909 days ago)
Due
Updated 05/13/2009 (5894 days ago)
Assigned 04/28/2009 (5909 days ago)
Resolved 05/13/2009 (5894 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch Yes

History
05/13/2009 04:18:59 PM Jan Schneider State ⇒ No Feedback
 
04/28/2009 07:28:21 AM Jan Schneider Comment #4
State ⇒ Feedback
Reply to this comment
Are you really still using FRAMEWORK_3 of Rdo? That code was only a 
showcase for upcoming features, the latest is in Git.
04/28/2009 04:42:37 AM tenorviol (at) yahoo (dot) com Comment #3 Reply to this comment
After poking around with this a bit more, I've realized that This only 
happens for MySQL tables that have not set their primary key field to 
auto_increment.  I'm still not convinced it'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] => [1] => admin [2] => actually [3] => do it [4] => 
1240893214 [5] => 1240893214 )
04/28/2009 03:24:00 AM tenorviol (at) yahoo (dot) com Comment #2 Reply to this comment
No also. Forgot to erase it. Thank you.
04/28/2009 03:21:32 AM tenorviol (at) yahoo (dot) com Comment #1
Priority ⇒ 2. Medium
Type ⇒ Bug
Summary ⇒ Rdo Mapper update function cannot create new records from Horde_Rdo_Base objects
Queue ⇒ Horde Framework Packages
Milestone ⇒
Patch ⇒ Yes
State ⇒ Unconfirmed
Reply to this comment
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->save();  // calls the mapper update function



Fatal error: Uncaught exception 'Horde_Rdo_Exception' with message 
'Column 'mytable_id' 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't imagine any negative 
effect here.



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

     {

         if ($object instanceof Horde_Rdo_Base) {

             $key = $this->model->key;

             $id = $object->$key;

             $fields = iterator_to_array($object);



             if (!$id) {

                 // Object doesn't exist yet; create it instead.

                 unset($fields[$key]);

                 $object = $this->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,

Saved Queries