diff --git a/README.en.md b/README.en.md index 8cd936e8cc52977185de915b45ffdd38d7586f00..9097085dcba8344d693b0bab1f320c65a5c141c2 100644 --- a/README.en.md +++ b/README.en.md @@ -34,9 +34,23 @@ Software architecture description #### Instructions -1. xxxx -2. xxxx -3. xxxx +1. 按月、按年分表的模型,皆不可使用 `with`,可使用 `load` 代替,`static::query` 会重新 实例化当前模型,之前设置的分表名称将被替换。 + + 具体原因看代码: +```php + /** + * Begin querying a model with eager loading. + * + * @param array|string $relations + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function with($relations) + { + return static::query()->with( + is_string($relations) ? func_get_args() : $relations + ); + } +``` #### Contribution diff --git a/README.md b/README.md index 92ed5e6e895cdcf71d83490c47c038df69e8d001..19737e281aee947040aa6c38c2ece772cce8f296 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,23 @@ #### 使用说明 -1. xxxx -2. xxxx -3. xxxx +1. 按月、按年分表的模型,皆不可使用 `with`,可使用 `load` 代替,`static::query` 会重新 实例化当前模型,之前设置的分表名称将被替换。 + + 具体原因看代码: +```php + /** + * Begin querying a model with eager loading. + * + * @param array|string $relations + * @return \Illuminate\Database\Eloquent\Builder + */ + public static function with($relations) + { + return static::query()->with( + is_string($relations) ? func_get_args() : $relations + ); + } +``` #### 参与贡献 diff --git a/app/Models/MonthModel.php b/app/Models/MonthModel.php index 34b9eb94ca2ab2e91057593c10597eefaa18722d..6e9ac9a82b4f0bf8b822089814246912269e443b 100644 --- a/app/Models/MonthModel.php +++ b/app/Models/MonthModel.php @@ -40,11 +40,9 @@ class MonthModel extends Model $month = str_replace('_', '-', $month); // 当表名大于最小表名时,设置表名。 - if ( $month >= str_replace('_', '-', self::MIN_TABLE) ) { - $this->month = date(self::MONTH_FORMAT, strtotime($month)); - $this->table = $this->getOldTableName() . '_' . $this->month; - } - + // if ( $month >= str_replace('_', '-', self::MIN_TABLE) ) {} + $this->month = date(self::MONTH_FORMAT, strtotime($month)); + $this->table = $this->getOldTableName() . '_' . $this->month; return $this; } diff --git a/app/Models/YearModel.php b/app/Models/YearModel.php index 9db7a50d3122f3707ae0565430a04b666028acb7..ce3f389a6b8c3de88f0f391dff982f146175fd46 100644 --- a/app/Models/YearModel.php +++ b/app/Models/YearModel.php @@ -41,10 +41,9 @@ class YearModel extends MonthModel $month = str_replace('_', '-', $month); // 当表名大于最小表名时,设置表名。 - if ( $month >= self::MIN_TABLE ) { - $this->month = $month; - $this->table = $this->getOldTableName() . '_' . $this->month; - } + // if ( $month >= self::MIN_TABLE ) {} + $this->month = $month; + $this->table = $this->getOldTableName() . '_' . $this->month; return $this; } diff --git a/app/Modules/Admin/Services/AdminLogService.php b/app/Modules/Admin/Services/AdminLogService.php index 7e8f2338d81d3c11292335675ca431a225a8f444..52ae544371d2c7d98d4878b5f4a576be275d18d7 100644 --- a/app/Modules/Admin/Services/AdminLogService.php +++ b/app/Modules/Admin/Services/AdminLogService.php @@ -14,7 +14,7 @@ class AdminLogService extends BaseService public function lists(array $params) : array { $model = $this->model->setMonthTable($this->getSearchMonth()) - ->with([ + ->load([ 'admin' => function($query) { $query->select('admin_id', 'admin_name'); }, diff --git a/app/Modules/Admin/Services/AdminLoginLogService.php b/app/Modules/Admin/Services/AdminLoginLogService.php index 59b94396282848e674b18ec13a9ac67fd4f3bcdd..c238df0643ffaa827df2c07f83e941240c35a28a 100644 --- a/app/Modules/Admin/Services/AdminLoginLogService.php +++ b/app/Modules/Admin/Services/AdminLoginLogService.php @@ -14,7 +14,7 @@ class AdminLoginLogService extends BaseService public function lists(array $params) : array { $model = $this->model->setMonthTable($this->getSearchMonth()) - ->with([ + ->load([ 'admin' => function($query) { $query->select('admin_id', 'admin_name'); },