Summary | Rdo throws inappropriate exception |
Queue | Horde Framework Packages |
Type | Bug |
State | Unconfirmed |
Priority | 1. Low |
Owners | |
Requester | birnbacs (at) gmail (dot) com |
Created | 05/27/2018 (2544 days ago) |
Due | |
Updated | 05/27/2018 (2544 days ago) |
Assigned | |
Resolved | |
Milestone | |
Patch | Yes |
State ⇒ Unconfirmed
Priority ⇒ 1. Low
Type ⇒ Bug
Summary ⇒ Rdo throws inappropriate exception
Queue ⇒ Horde Framework Packages
Milestone ⇒
Patch ⇒ Yes
Among the problems I encounterd using a ONE_TO_ONE lazy relationship
is one where "a serious error" problem occurs when the target of the
relationship does not exist.
IOW I have an Rdo object A with a ONE_TO_ONE lazy relationship to Rdo
object B. If there is no object B an error is thrown upon any attempt
to access B (like in (if empty(B) { do_somthing }). This does not seem
to happen with any of the other relationships and it also appears to
be out of place.
I commented out line 132 where the Exception is thrown:
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']}));
// amended SB 2018-05-23 to fix ONE_TO_ONE access problem
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;
Please note that the above code comprises another fix I introduced
recently (bug report pending).
I cannot see a situation where an empty result to the findOne() should
cause an exception - but am of course eager to learn the better.