This commit is contained in:
2020-11-10 00:18:45 +08:00
parent 27a2e23bef
commit d07c39007d
+14 -4
View File
@@ -6,6 +6,7 @@
* Time: 14:56 * Time: 14:56
*/ */
declare(strict_types=1); declare(strict_types=1);
namespace Database\Traits; namespace Database\Traits;
@@ -224,9 +225,12 @@ trait QueryTrait
* @return $this * @return $this
* @throws Exception * @throws Exception
*/ */
public function leftJoin($tableName, $alias, $onCondition, $param = NULL) public function leftJoin(string $tableName, string $alias, $onCondition, $param = NULL)
{ {
if ($tableName instanceof ActiveRecord) { if (class_exists($tableName)) {
if (!in_array(ActiveRecord::class, class_implements($tableName))) {
throw new Exception('Model must implement ' . $tableName);
}
$tableName = $tableName::getTable(); $tableName = $tableName::getTable();
} }
return $this->join(...["LEFT JOIN " . $tableName, $alias, $onCondition, $param]); return $this->join(...["LEFT JOIN " . $tableName, $alias, $onCondition, $param]);
@@ -242,7 +246,10 @@ trait QueryTrait
*/ */
public function rightJoin($tableName, $alias, $onCondition, $param = NULL) public function rightJoin($tableName, $alias, $onCondition, $param = NULL)
{ {
if ($tableName instanceof ActiveRecord) { if (class_exists($tableName)) {
if (!in_array(ActiveRecord::class, class_implements($tableName))) {
throw new Exception('Model must implement ' . $tableName);
}
$tableName = $tableName::getTable(); $tableName = $tableName::getTable();
} }
return $this->join(...["RIGHT JOIN " . $tableName, $alias, $onCondition, $param]); return $this->join(...["RIGHT JOIN " . $tableName, $alias, $onCondition, $param]);
@@ -258,7 +265,10 @@ trait QueryTrait
*/ */
public function innerJoin($tableName, $alias, $onCondition, $param = NULL) public function innerJoin($tableName, $alias, $onCondition, $param = NULL)
{ {
if ($tableName instanceof ActiveRecord) { if (class_exists($tableName)) {
if (!in_array(ActiveRecord::class, class_implements($tableName))) {
throw new Exception('Model must implement ' . $tableName);
}
$tableName = $tableName::getTable(); $tableName = $tableName::getTable();
} }
return $this->join(...["INNER JOIN " . $tableName, $alias, $onCondition, $param]); return $this->join(...["INNER JOIN " . $tableName, $alias, $onCondition, $param]);