mirror of
https://gitee.com/fastadminnet/framework.git
synced 2026-07-01 12:42:48 +08:00
改进Model类 支持动态查询调用
This commit is contained in:
@@ -859,10 +859,10 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
|
||||
/**
|
||||
* 初始化数据库对象
|
||||
* @access public
|
||||
* @access protected
|
||||
* @return \think\db\Query
|
||||
*/
|
||||
public static function db()
|
||||
protected static function db()
|
||||
{
|
||||
$model = get_called_class();
|
||||
if (!isset(self::$links[$model])) {
|
||||
@@ -894,7 +894,7 @@ abstract class Model implements \JsonSerializable, \ArrayAccess
|
||||
call_user_func_array([$this, $method], $args);
|
||||
return $this;
|
||||
} else {
|
||||
throw new Exception(__CLASS__ . ':' . $method . ' method not exist');
|
||||
return call_user_func_array([self::db(), $method], $args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,7 +66,7 @@ class Merge extends Model
|
||||
|
||||
foreach (static::$relationModel as $key => $model) {
|
||||
$name = is_int($key) ? $model : $key;
|
||||
$table = is_int($key) ? self::db()->getTable($name) : $model;
|
||||
$table = is_int($key) ? $query->getTable($name) : $model;
|
||||
$query->join($table . ' ' . $name, $name . '.' . $class->fk . '=' . $master . '.' . $class->getPk());
|
||||
$fields = self::getModelField($name, $table, $class->mapFields);
|
||||
$query->field($fields);
|
||||
|
||||
Reference in New Issue
Block a user