Forum

[API Bug] Values of...
 
Notifications
Clear all

[API Bug] Values of SqlElements inside a SqlElements aren't fetched

3 Posts
2 Users
0 Reactions
3,933 Views
(@simon-tremblay)
Posts: 5
Active Member
Topic starter
 
[#1640]

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:


 
Posted : 21 Feb 2014 18H58
(@babynus)
Posts: 14952
Member Admin
 

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.


 
Posted : 23 Feb 2014 14H16
(@babynus)
Posts: 14952
Member Admin
 

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:


 
Posted : 01 Mar 2014 15H55
Share:

Scroll to Top