Fixed Model joins

This commit is contained in:
2021-12-20 23:34:52 -03:00

View File

@ -79,7 +79,7 @@ class Model {
'table' => $j['table'] ?? $j[0], 'table' => $j['table'] ?? $j[0],
'from' => $j['from'] ?? $j[1], 'from' => $j['from'] ?? $j[1],
'to' => $j['to'] ?? $j[2], 'to' => $j['to'] ?? $j[2],
'sym' => $j['sym'] ?? ($j[3] ?? '='), 'symb' => $j['symb'] ?? ($j[3] ?? '='),
'alias' => $j['alias'] ?? '', 'alias' => $j['alias'] ?? '',
'type' => strtolower($j['type'] ?? ''), 'type' => strtolower($j['type'] ?? ''),
'params' => $j['params'] ?? '' 'params' => $j['params'] ?? ''
@ -97,7 +97,7 @@ class Model {
$cond = (object) [ $cond = (object) [
'column' => $c['column'] ?? $c[0], 'column' => $c['column'] ?? $c[0],
'value' => $c['value'] ?? $c[1], 'value' => $c['value'] ?? $c[1],
'sym' => strtolower($c['sym'] ?? ($c[2] ?? '=')), 'symb' => strtolower($c['symb'] ?? ($c[2] ?? '=')),
'type' => strtolower($c['type'] ?? '') 'type' => strtolower($c['type'] ?? '')
]; ];
$this->conditions []= $cond; $this->conditions []= $cond;
@ -154,7 +154,7 @@ class Model {
return $orm; return $orm;
} }
foreach ($this->columns as $col) { foreach ($this->columns as $col) {
$orm = $orm->select(trim(implode('.', $col), '.')); $orm = $orm->select(trim(implode('.', (array) $col), '.'));
} }
return $orm; return $orm;
} }
@ -192,7 +192,7 @@ class Model {
} }
if ($join->type == 'raw') { if ($join->type == 'raw') {
$orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to], $join->alias, $join->params); $orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to], $join->alias, $join->params);
} elseif ($join->alias === '') { } elseif ($join->alias !== '') {
$orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to], $join->alias); $orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to], $join->alias);
} else { } else {
$orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to]); $orm = $orm->{$method}($join->table, [$join->from, $join->symb, $join->to]);
@ -206,7 +206,7 @@ class Model {
} }
foreach ($this->conditions as $cond) { foreach ($this->conditions as $cond) {
$method = 'where'; $method = 'where';
switch ($cond->sym) { switch ($cond->symb) {
case '<': case '<':
$method = 'whereLt'; $method = 'whereLt';
break; break;