priority
Standard
status
Closed
resolution
Won't Fix

qcodo
0.4.10 (stable)
category
General Framework
php
5.2.10
database
MySQL
webserver
Apache
os
Linux
browser
Firefox 3.5.3

Votes
There are no votes for this issue.
Example Code

Event::QueryArray(
   QQ::Equal(QQN::Event->Id, 1),
   QQ::Clause(
       QQ::Expand(QQN::Event->Plan),
               QQ::ExpandAsArray(QQN::Event->Plan->PlanDetailsAsPlan)
   )
Example Data
Event
 10, 1
 
Plan
 1, 'My Plan'

PlanDetails
 100, 1, 'detail 1'
 101, 1, 'detail 2'
Expected Output
Single Event object with Event->Plan containing plan information and Event->Plan->_objobjPlanDetailsAsPlanArray containing 2 entries of PlanDetails
Actual Output
Single Event object with Event->Plan containing plan information and Event->Plan->_objobjPlanDetailsAsPlanArray containing only the first of the details

reported: tuesday, february 16, 2010, 11:30 pm pst  |  by: brocha  |  messages: 6 messages  |  last: about 22 days ago


#1  |  brocha
Tuesday, February 16, 2010, 11:30 PM PST

I have the following 3 tables:

Event
id (PK)
plan_id (FK to Plan)

Plan
id (PK)
name

PlanDetails
 id (PK)
 plan_id (FK to Plans)
 some_info

I want to query an event by ID and expand the plan and PlanDetails associated with the event. But only the first of the PlanDetail records gets loaded.


The query that is produced is correct and returns 2 records because there are 2 details. But resulting object has only one detail populated inside Plan's __objPlanDetailsAsPlanArray.

I have tried removing the QQ::Expand(QQN::Event->Plan) clause and that has no effect.

(I am using QueryArray because QuerySingle populates __objPlanDetailsAsPlan. I saw this is a known bug that has a patch for it. But this does not seem to be related.)

When i query Plan directly and ExpandAsArray  on PlanDetailsAsPlan  this works correctly and i get 2 PlanDetails.

QCodo 0.4.10

#2  |  bfossil Malaysia
Thursday, July 29, 2010, 1:27 AM PDT

I encountered the same problem. Qcubed does have a solution to this. Copy the following 2 files from Qcubed version 1.0

qcodo/_core/codegen/templates/db_orm/class_gen/qcodo_query_methods.tpl
qcodo/_core/codegen/templates/db_orm/class_gen/instantiation_methods.tpl

and place it to

qcodo/codegen/templates/db_orm/class_gen/qcodo_query_methods.tpl
qcodo/codegen/templates/db_orm/class_gen/instantiation_methods.tpl

After that re-codegen and it shall solve the problem.

The root cause is because InstantiateDbRow does not further expand nodes more than 2 levels. Perhaps this fix from Qcubed should be applied to Qcodo ?

#3  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Wednesday, August 11, 2010, 8:50 AM PDT

THanks for the posts...

I've added the support so that QuerySingle now does ExpandAsArray.

However, taking a look at the code you suggested from QCubed for a ExpandAsArray support on a linked object... if I'm seeing the code correctly (which I've been known to do incorrectly, so please do correct me if I am wrong =) this will cause quite a bit of performance lag as it's now needing to keep track and compare against the entire result set to check on expansions EVERY time.  Especially as your data sets get larger, this will become, in essence, an N-squared algorithm, which is not ideal.

I thought about the idea of only having it perform the analysis if it knows for sure that there is ExpandAsArray going on (e.g. putting the entire check around an if() statement) -- however, that means that any time you do an ExpandAsArray, even the simple case one, you end up with an N-squared algorithm to perform the expansion.  That performance lag specifically counteracts the optimization you would normally be doing with ExpandAsArray in the first place.

I checked and I can't find it in my personal notes, but if memory serves, I believe I went with the current approach of ExpandAsArray specifically because of this issue.  In short, it may be very very difficult to correctly perform a nested ExpandAsArray as the original poster is requesting in a way that doesn't take a performance hit.  The bottom line is that to do ExpandAsArray efficiently, you really must limit the analysis to the row immediately preceding the current row -- but to do ExpandAsArray in a nested fashion, you'll need to send back the entire resultset every time you examine a row... which is the source of the performance issue.

I'm going to go ahead and specify this bug as fixed (since we've gone ahead and fixed the QuerySingle issue)... but if you want to discuss further, please feel free to post here.

#4  |  ‹‹ Qcodo System Message ››
Wednesday, August 11, 2010, 8:50 AM PDT

Mike Ho made edits to the issue, including:

  • Status changed from New Issue to Fixed
#5  |  ‹‹ Qcodo System Message ››
Wednesday, August 11, 2010, 8:50 AM PDT

Mike Ho made edits to the issue, including:

  • Status changed from Fixed to Closed
  • Resolution changed from none to Won't Fix
#6  |  Mike Ho (Sunnyvale, CA) United States of America Qcodo Administrator
Wednesday, August 11, 2010, 8:51 AM PDT

Actually, on second thought after re-reading the post itself, I've reclassified as “Won't Fix”, since it makes more sense given the specific content of this issue ticket.  But as a head's up, the QuerySingle fix is still in place though, and will be in the next 0.4.17 release.



Copyright © 2005 - 2010, Quasidea Development, LLC
This open-source framework for PHP is released under the terms of The MIT License.