Allow change from on ModelMySQL.

This commit is contained in:
kj 2020-03-27 10:25:40 -04:00
parent f6c82c7a8c
commit 2d377eb803
1 changed files with 90 additions and 65 deletions

View File

@ -85,6 +85,7 @@ class ModelMySQL {
static::$querySelect = [
'select' => '*',
'where' => '',
'from' => '',
'leftJoin' => '',
'rightJoin' => '',
'innerJoin' => '',
@ -103,7 +104,13 @@ class ModelMySQL {
* Contiene la sentencia SQL.
*/
private static function buildQuery() {
$sql = 'SELECT '.static::$querySelect['select'].' FROM '.static::table();
$sql = 'SELECT '.static::$querySelect['select']:
if (static::$querySelect['from'] != '') {
$sql .= ' FROM '.static::$querySelect['from'];
} else {
$sql .= ' FROM '.static::table();
}
if (static::$querySelect['leftJoin'] != '') {
$sql .= static::$querySelect['leftJoin'];
@ -289,6 +296,24 @@ class ModelMySQL {
return new static();
}
/*
* Define FROM en la sentencia SQL.
*
* @param array $tables
* Tablas que se selecionarán en la consulta SQL.
*/
public static function from($tables) {
$db = static::db();
$from = [];
foreach($tables as $table) {
$from[] = $db->real_escape_string($table);
}
static::$querySelect['from'] = join(', ', $from);
return new static();
}
/*
* Define el WHERE en la sentencia SQL.
*