6.0.0-git
2018-12-16

[#14818] Rdo access problem in ONE_TO_ONE relationship
Summary Rdo access problem in ONE_TO_ONE relationship
Queue Horde Framework Packages
Type Bug
State Unconfirmed
Priority 1. Low
Owners
Requester birnbacs (at) gmail (dot) com
Created 2018-05-23 (207 days ago)
Due
Updated 2018-05-23 (207 days ago)
Assigned
Resolved
Milestone
Patch Yes

History
2018-05-23 09:42:11 birnbacs (at) gmail (dot) com Comment #1
Type ⇒ Bug
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Summary ⇒ Rdo access problem in ONE_TO_ONE relationship
Queue ⇒ Horde Framework Packages
Milestone ⇒
Patch ⇒ Yes
Reply to this comment
When using a ONE_TO_ONE relationship in Rdo I could not access a 
related data field. I tracked the problem down to Base.php, function 
__get(). Consider lines 122 to 136 where a SQL search for the attached 
record is conducted:

         switch ($rel['type']) {
         case Horde_Rdo::ONE_TO_ONE:
         case Horde_Rdo::MANY_TO_ONE:
             if (isset($rel['query'])) {
                 $query = $this->_fillPlaceholders($rel['query']);
                 $this->_fields[$field] = $m->findOne($query);
             } elseif (!empty($this->{$rel['foreignKey']})) {
                 //$this->_fields[$field] = 
$m->findOne($this->{$rel['foreignKey']});
                 $this->_fields[$field] = 
$m->findOne(array($rel['foreignKey'] => $this->{$rel['foreignKey']}));
                 if (empty($this->_fields[$field])) {
                     throw new Horde_Rdo_Exception('The referenced 
object with key ' . $this->{$rel['foreignKey']} . ' does not exist. 
Your data is inconsistent');
                 }
             } else {
                 $this->_fields[$field] = null;
             }
             break;

For unknown reasons everything works for a MANY_TO_ONE relationship, 
using the same code.
Anyway, I used the available information to define a more specific 
search in line 129:

$this->_fields[$field] = $m->findOne(array($rel['foreignKey'] => 
$this->{$rel['foreignKey']}));

and this made it work for all types of relationship.

Saved Queries