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 |
State ⇒ Feedback
showcase for upcoming features, the latest is in Git.
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 )
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
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,