Skip to content

Commit

Permalink
Merge pull request #156 from ThibBal/3.4
Browse files Browse the repository at this point in the history
[fix] Check if the path exists only if no $hint_path is provided
  • Loading branch information
moufmouf authored Jun 21, 2018
2 parents 82f8aff + e711f19 commit 38dd8e5
Showing 1 changed file with 28 additions and 26 deletions.
54 changes: 28 additions & 26 deletions src/Mouf/Database/TDBM/TDBMService.php
Original file line number Diff line number Diff line change
Expand Up @@ -1465,32 +1465,34 @@ public function getObjectsByMode($mode, $table_name, $filter_bag=null, $orderby_
}
}


// Now, for each needed table to perform the order by, we must verify if the relationship between the order by and the object is indeed a 1* relationship
foreach ($needed_table_array_for_orderby as $target_table_table) {
// Get the path between the main table and the target group by table

// TODO! Pas bon!!!! Faut le quérir, hélas!
// Mais comment gérer ça sans plomber les perfs et en utilisant le path fourni?????
$path = $this->getPathFromCache($table_name, $target_table_table);

/**********************************
* Modifier par Marc de *1 vers 1*
* (sur les conseils de David !)
*/
$is_ok = true;
foreach ($path as $step) {
if ($step["type"]=="1*") {
$is_ok = false;
break;
}
}

if (!$is_ok) {
throw new TDBMException("Error in querying database from getObjectsByFilter. You tried to order your data according to a column of the '$target_table_table' table. However, the '$target_table_table' table has a many to 1 relationship with the '$table_name' table. This means that one '$table_name' object can contain many '$target_table_table' objects. Therefore, trying to order '$table_name' objects using '$target_table_table' objects is meaningless and cannot be performed.");
}
}
//If no $hint_path is provided, check that a path exists
if($hint_path === null){
// Now, for each needed table to perform the order by, we must verify if the relationship between the order by and the object is indeed a 1* relationship
foreach ($needed_table_array_for_orderby as $target_table_table) {
// Get the path between the main table and the target group by table

// TODO! Pas bon!!!! Faut le quérir, hélas!
// Mais comment gérer ça sans plomber les perfs et en utilisant le path fourni?????
$path = $this->getPathFromCache($table_name, $target_table_table);

/**********************************
* Modifier par Marc de *1 vers 1*
* (sur les conseils de David !)
*/
$is_ok = true;
foreach ($path as $step) {
if ($step["type"]=="1*") {
$is_ok = false;
break;
}
}

if (!$is_ok) {
throw new TDBMException("Error in querying database from getObjectsByFilter. You tried to order your data according to a column of the '$target_table_table' table. However, the '$target_table_table' table has a many to 1 relationship with the '$table_name' table. This means that one '$table_name' object can contain many '$target_table_table' objects. Therefore, trying to order '$table_name' objects using '$target_table_table' objects is meaningless and cannot be performed.");
}
}
}

// In a SELECT DISTINCT ... ORDER BY ... clause, the orderbyed columns must appear!
// Therefore, we must be able to parse the Orderby columns requested, give them dummy names and remove them afterward!
Expand Down

0 comments on commit 38dd8e5

Please sign in to comment.