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

Ralf Lang lang at b1-systems.de
Wed Jan 18 19:14:48 UTC 2012


Am 13.01.2012 11:09, schrieb Ralf Lang:
> Hi List,
> Ticket URL: http://bugs.horde.org/ticket/10880
>> ------------------------------------------------------------------------------ 
>>
>>  Ticket             | 10880
>>  Updated 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              | Feedback
>>  Priority           | 1. Low
>>  Milestone          |
>>  Patch              |
>>  Owners             |
>> ------------------------------------------------------------------------------ 
>>
>>
>>
>> Ralf Lang (B1 Systems GmbH) <lang at b1-systems.de> (2012-01-09 21:31) 
>> wrote:
>>
>> It seems like lazy [one|many]_to_one relations are resolved by a 
>> different part of code than eager relations.
>>
>> lazy relations:
>> Base.php __get triggers a findOne on the target mapper with either a 
>> supplied query object (undocumented?) or the defined foreignKey 
>> field's value. A findOne without restrictions catches the first 
>> object, if any exist or null otherwise. I think I have fixed THIS
>>
>> eager relations:
>> REFERENCING Objects with broken eager relations of either type (null 
>> value or wrong key value) simply aren't created. No exception is 
>> thrown until code wants to access the object's properties.
>> This seems to be handled by Horde_Rdo_Query generating an INNER JOIN 
>> which results in no object
>> No idea how to tackle this.
>>
>>
>>
>>
> 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.

-- 
Ralf Lang
Linux Consultant / Developer
Tel.: +49-170-6381563
Mail: lang at b1-systems.de

B1 Systems GmbH
Osterfeldstraße 7 / 85088 Vohburg / http://www.b1-systems.de
GF: Ralph Dehner / Unternehmenssitz: Vohburg / AG: Ingolstadt,HRB 3537



More information about the dev mailing list