Hello,
I was trying the new API from version 4.1. I tried to retrieve progress of all of my projects and it happened that it returns to me 0. I found that progress is not a variable from Project but it is a variable from a PlanningElement that is a member variable of Project.
So I assumed that only the data for Project was retrieved from database and not the one for the other sql elements inside a Project...
You will find my attempt to fix that bug with a patch attached with this post (I work with git).
Basically, I defined a new function
getAllSqlElementsFromCriteria
We must define it for each SqlElements containing other SqlElements. Surely there is a better way to achieve that...
Here it is how I fixed Project (I know there is other SqlElements than Project that contains SqlElements but I don't use them for now):
public function getAllSqlElementsFromCriteria($critArray, $initializeIfEmpty=false, $clauseWhere=null, $clauseOrderBy=null,
$getIdInKey=false, $withoutDependentObjects=false, $maxElements=null) {
$projects = array();
$projects = parent::getAllSqlElementsFromCriteria($critArray, $initializeIfEmpty, $clauseWhere, $clauseOrderBy,
$getIdInKey, $withoutDependentObjects, $maxElements);
foreach ($projects as $project) {
$project->ProjectPlanningElement = SqlElement::getSingleSqlElementFromCriteria('ProjectPlanningElement', array('refType'=>'Project', 'refId'=>$project->id));
}
return $projects;
}
The patch:
Hi,
Thanks for this analysis.
Your solution is a good workaround, but as you wrote, I think there is more simple.
I'll have a look.
Ticket 1306 recorded.
In the end, fixing is much more simple. :woohoo:
In /model/persistence/SqlElement.php, replace lines 1458 :
if (! $withoutDependentObjects) {
$obj->getDependantSqlElement($col_name);
}
with
if (! $withoutDependentObjects) {
$obj->$col_name=$obj->getDependantSqlElement($col_name);
}
In fact, it was a bug 🙁
and an old one... :blush: