[Tickets #10880] Rdo: Make *- to-one-relations aware of "no relation" state

bugs at horde.org bugs at horde.org
Thu Dec 22 18:05:12 UTC 2011


DO NOT REPLY TO THIS MESSAGE. THIS EMAIL ADDRESS IS NOT MONITORED.

Ticket URL: http://bugs.horde.org/ticket/10880
------------------------------------------------------------------------------
  Ticket             | 10880
  Created By         | Ralf Lang (B1 Systems GmbH) <lang at b1-systems.de>
  Summary            | Rdo: Make *- to-one-relations aware of "no relation"
                     | state
  Queue              | Horde Framework Packages
  Version            | Git master
  Type               | Enhancement
  State              | New
  Priority           | 1. Low
  Milestone          |
  Patch              |
  Owners             |
------------------------------------------------------------------------------


Ralf Lang (B1 Systems GmbH) <lang at b1-systems.de> (2011-12-22 19:05) wrote:

I feel the current behaviour of Horde_Rdo resolving to-one-relations  
for the corner case of NULL or "empty string" in the relation key  
field is misleading.

Example:

Two data entities exist, a network host table and a certificate table.
A host may or may not have a certificate.

Since certificates are managed for other objects too it is not
feasible to reverse the relation and say the certificate must  
reference the host.

CREATE TABLE `appname_hosts` (
   `host_id` int(10) NOT NULL auto_increment,
   `certificate_id` int(10) default NULL,
#[... more fields that don't matter here]
   PRIMARY KEY  (`host_id`)
) ENGINE=MyISAM AUTO_INCREMENT=125 DEFAULT CHARSET=latin1

CREATE TABLE `appname_certificates` (
   `certificate_id` int(10) unsigned NOT NULL auto_increment,
   `certificate_crt` text,
   `certificate_key` text,
   `ca_id` int(10) default NULL,
   `certificate_cn` varchar(100) default NULL,
   `certificate_csr` text,
   `certificate_pkcs12` text,
   PRIMARY KEY  (`certificate_id`)
) ENGINE=MyISAM AUTO_INCREMENT=151 DEFAULT CHARSET=latin;

Now we have a Appname_HostMapper Class with relation

     protected $_lazyRelationships = array(
         'certificate' => array('type' => Horde_Rdo::ONE_TO_ONE,
                           'foreignKey' => 'certificate_id',
                           'mapper' => 'Appname_CertificateMapper')
     );

Now when I have a Host table entry with value of '' or NULL, I do get  
an instance of Appname_Certificate as a response, usually the first  
entry in the table (with default order).

Rdo currently doesn't understand the concept of a missing relation.
I'd suggest to either return no object or an exception.
Consistence with to-many-relations is hard.
These relations always return a list object, possibly an empty one.
As to-one-relations are often used in chains (at least in my code) I'd  
prefer a clean exception over an empty result but the current  
situation is worst for me.

My current workaround is to check length($this->certificate_id) before  
accessing $this->certificate but it's obviously not a clean solution.

I've classified this as an enhancement rather than a bug because it  
breaks current behaviour and Rdo possibly wasn't designed with this  
case in mind.





More information about the bugs mailing list