[Tickets #8225] Rdo Mapper update function cannot create new records from Horde_Rdo_Base objects
bugs at horde.org
bugs at horde.org
Tue Apr 28 03:21:33 UTC 2009
DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.
Ticket URL: http://bugs.horde.org/ticket/8225
------------------------------------------------------------------------------
Ticket | 8225
Created By | tenorviol at yahoo.com
Summary | Rdo Mapper update function cannot create new records
| from Horde_Rdo_Base objects
Queue | Horde Framework Packages
Version | FRAMEWORK_3
Type | Bug
State | Unconfirmed
Priority | 2. Medium
Milestone |
Patch | 1
Owners |
------------------------------------------------------------------------------
tenorviol at yahoo.com (2009-04-27 23:21) wrote:
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,
More information about the bugs
mailing list