Fix device_groups in alert/group builder (#10643)

This commit is contained in:
Tony Murray
2019-10-02 13:54:54 +00:00
committed by GitHub
parent 74724a4618
commit ef4e6de867
3 changed files with 12 additions and 8 deletions

View File

@@ -430,7 +430,8 @@ class QueryBuilderParser implements \JsonSerializable
}
if (!$this->schema->columnExists($child, $child_key)) {
echo"FIXME: Could not make glue from $child to $parent\n";
$child_key = $this->schema->getPrimaryKey($child);
\Log::warning("QueryBuilderParser: Warning, guessing glue from $child.$child_key to $parent.$parent_key");
}
}

View File

@@ -89,19 +89,14 @@ class Schema
* Get the primary key column(s) for a table
*
* @param string $table
* @return string|array if a single column just the name is returned, otherwise an array of column names
* @return string if a single column just the name is returned, otherwise the first column listed will be returned
*/
public function getPrimaryKey($table)
{
$schema = $this->getSchema();
$columns = $schema[$table]['Indexes']['PRIMARY']['Columns'];
if (count($columns) == 1) {
return reset($columns);
}
return $columns;
return reset($columns);
}
public function getSchema()

View File

@@ -180,4 +180,12 @@
"SELECT * FROM locations,devices WHERE (devices.device_id = ? AND locations.id = devices.location_id) AND locations.location REGEXP \"somewhere\"",
["select * from `devices` left join `locations` on `locations`.`id` = `devices`.`location_id` where (`locations`.`location` REGEXP ?)", ["somewhere"]]
]
,
[
"%device_groups.id = 1",
{"condition":"AND","rules":[{"id":"device_groups.id","field":"device_groups.id","type":"string","input":"text","operator":"equal","value":"1"}],"valid":true},
"device_groups.id = 1",
"SELECT * FROM devices,device_group_device,device_groups WHERE (devices.device_id = ? AND devices.device_id = device_group_device.device_id AND device_group_device.device_group_id = device_groups.id) AND device_groups.id = 1",
["select * from `devices` left join `device_group_device` on `devices`.`device_id` = `device_group_device`.`device_id` left join `device_groups` on `device_group_device`.`device_group_id` = `device_groups`.`id` where (`device_groups`.`id` = ?)", ["1"]]
]
]