allow table alias into commonObject getFieldList
This commit is contained in:
parent
3baf0e66b9
commit
bcbf8bb72a
@ -7467,12 +7467,22 @@ abstract class CommonObject
|
|||||||
/**
|
/**
|
||||||
* Function to concat keys of fields
|
* Function to concat keys of fields
|
||||||
*
|
*
|
||||||
|
* @param array $alias content informations of field
|
||||||
|
*
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
protected function getFieldList()
|
protected function getFieldList($alias = 't')
|
||||||
{
|
{
|
||||||
$keys = array_keys($this->fields);
|
$keys = array_keys($this->fields);
|
||||||
return implode(',', $keys);
|
if (!empty($alias)) {
|
||||||
|
$keys_with_alias = array();
|
||||||
|
foreach ($keys as $fieldname) {
|
||||||
|
$keys_with_alias[] = $alias . '.' . $fieldname;
|
||||||
|
}
|
||||||
|
return implode(',', $keys_with_alias);
|
||||||
|
} else {
|
||||||
|
return implode(',', $keys);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -7646,13 +7656,13 @@ abstract class CommonObject
|
|||||||
{
|
{
|
||||||
if (empty($id) && empty($ref) && empty($morewhere)) return -1;
|
if (empty($id) && empty($ref) && empty($morewhere)) return -1;
|
||||||
|
|
||||||
$sql = 'SELECT '.$this->getFieldList();
|
$sql = 'SELECT '.$this->getFieldList('t');
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element;
|
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
||||||
|
|
||||||
if (!empty($id)) $sql .= ' WHERE rowid = '.$id;
|
if (!empty($id)) $sql .= ' WHERE t.rowid = '.$id;
|
||||||
elseif (!empty($ref)) $sql .= " WHERE ref = ".$this->quote($ref, $this->fields['ref']);
|
elseif (!empty($ref)) $sql .= " WHERE t.ref = ".$this->quote($ref, $this->fields['ref']);
|
||||||
else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare
|
else $sql .= ' WHERE 1 = 1'; // usage with empty id and empty ref is very rare
|
||||||
if (empty($id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' AND entity IN ('.getEntity($this->table_element).')';
|
if (empty($id) && isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' AND t.entity IN ('.getEntity($this->table_element).')';
|
||||||
if ($morewhere) $sql .= $morewhere;
|
if ($morewhere) $sql .= $morewhere;
|
||||||
$sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record
|
$sql .= ' LIMIT 1'; // This is a fetch, to be sure to get only one record
|
||||||
|
|
||||||
@ -7695,9 +7705,9 @@ abstract class CommonObject
|
|||||||
|
|
||||||
$objectline = new $objectlineclassname($this->db);
|
$objectline = new $objectlineclassname($this->db);
|
||||||
|
|
||||||
$sql = 'SELECT '.$objectline->getFieldList();
|
$sql = 'SELECT '.$objectline->getFieldList('l');
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.$objectline->table_element;
|
$sql .= ' FROM '.MAIN_DB_PREFIX.$objectline->table_element.' as l';
|
||||||
$sql .= ' WHERE fk_'.$this->element.' = '.$this->id;
|
$sql .= ' WHERE l.fk_'.$this->element.' = '.$this->id;
|
||||||
if ($morewhere) $sql .= $morewhere;
|
if ($morewhere) $sql .= $morewhere;
|
||||||
|
|
||||||
$resql = $this->db->query($sql);
|
$resql = $this->db->query($sql);
|
||||||
|
|||||||
@ -403,7 +403,7 @@ class MyObject extends CommonObject
|
|||||||
$records = array();
|
$records = array();
|
||||||
|
|
||||||
$sql = 'SELECT ';
|
$sql = 'SELECT ';
|
||||||
$sql .= $this->getFieldList();
|
$sql .= $this->getFieldList('t');
|
||||||
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
|
||||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
|
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN ('.getEntity($this->table_element).')';
|
||||||
else $sql .= ' WHERE 1 = 1';
|
else $sql .= ' WHERE 1 = 1';
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user