[dev] [Tickets #10880] Rdo drops objects from result when eager relation target is NULL or invalid key

Chuck Hagenbuch chuck at horde.org
Mon Feb 20 21:58:52 UTC 2012


Quoting Ralf Lang <lang at b1-systems.de>:

>>> I've been thinking about this for a while now. The lazy relation thing
>>> is fixed: Accessing a to-one-relation where the reference key is
>>> invalid (does not exist) now throws Rdo Exception, accessing a
>>> reference key of NULL returns null instead of the first possible object.
>>>
>>> I have no clear strategy to fix eager relations:
>>> As my test cases show, Objects which reference either NULL keys or
>>> invalid keys will simply not be loaded from database although they exist.
>>>
>>> An idea would be to use the lazy loading code but execute it
>>> immediately (will be slower than join for larger data sets).
>>> Is there a portable Sql which says "take result of join result table
>>> but add distinct keys from another sql statement"?
>>>
>> Why don't we do a LEFT JOIN with a WHERE clause instead of an INNER JOIN
>> for ? I haven't checked this performance-wise but at least we would not
>> lose LHS items which have no valid RHS items this way.
>>
>> I really like Horde_Rdo and I used it for paid work. In fact I am using
>> it now and experience its limits. I've created a branch Horde_Rdo_Fixes:
>>
>> My Idea:
>>
>> * Base Items should always be returned by a search, ignoring if (eager)
>> related items are found (currently non-matching eager relations make
>> missing result lines)
>> * Wrong references (relation keys) should always throw exceptions if
>> explicitly asked for but silently turned to null or (no result line)
>> otherwise (in ->save() and the likes)
>> * void references (relation keys) should not throw an exception but
>> either null (to one relation) or a list without the missing item (to
>> many relation).
>>
>> I'll do this as time permits or objectives require but any 2nd pair of
>> eyes is welcome as well as critizism of my understanding what Rdo should
>> do.
>>
>
> I've been re-thinking this. To-Many-Relations always return a  
> Horde_Rdo_List object over which you can savely iterate even if it's  
> empty.
>
> To-One-relations are often used in longer chains
>
> $baby->mother->granny->granny_age;
>
> At least I would do it this way in perl, with eval() and supplying  
> an exception object reference in the die() scalar - roughly the same  
> as an exception in php.
>
> In php, I get a php fatal when I access a method on a null response.  
> I cannot catch this.
>
> If the mother->granny relation is empty, I would like to get an  
> exception. I have to check for failure either way. But with an  
> exception, I only have one try()/catch() instead of two levels of if  
> (!($related = $object->relation)) { continue; }
>
> Now that we have the Horde 5 BC break opportunity, I think it would  
> be more useful to go the exception route.
>
> What do you think?
>
> Does this affect existing Horde llc apps?

Rdo still isn't used too widely, so it probably wouldn't.

I'm hesitant to make this an exception, though. I see your use case,  
but for non-nested use, it means that I have to put a try/catch around  
property testing when I could otherwise just use if checks (duck  
typing, etc)...

-chuck


More information about the dev mailing list