From 3c80a5415afa738b46a816f5d14f4a1f28d0618b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E4=B8=91=E8=B7=AF=E4=BA=BA?= <2278757482@qq.com> Date: Thu, 4 Feb 2021 18:34:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8C=89=E6=9C=88=E3=80=81=E6=8C=89=E5=B9=B4?= =?UTF-8?q?=E5=88=86=E8=A1=A8=E7=9A=84=E6=A8=A1=E5=9E=8B=EF=BC=8C=E7=9A=86?= =?UTF-8?q?=E4=B8=8D=E5=8F=AF=E4=BD=BF=E7=94=A8=20`with`=EF=BC=8C=E5=8F=AF?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=20`load`=20=E4=BB=A3=E6=9B=BF,`static::query?= =?UTF-8?q?`=20=E4=BC=9A=E9=87=8D=E6=96=B0=20=E5=AE=9E=E4=BE=8B=E5=8C=96?= =?UTF-8?q?=E5=BD=93=E5=89=8D=E6=A8=A1=E5=9E=8B=EF=BC=8C=E4=B9=8B=E5=89=8D?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=9A=84=E5=88=86=E8=A1=A8=E5=90=8D=E7=A7=B0?= =?UTF-8?q?=E5=B0=86=E8=A2=AB=E6=9B=BF=E6=8D=A2=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 具体原因看代码: ```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 ); } ``` --- README.en.md | 20 ++++++++++++++++--- README.md | 20 ++++++++++++++++--- app/Models/MonthModel.php | 8 +++----- app/Models/YearModel.php | 7 +++---- .../Admin/Services/AdminLogService.php | 2 +- .../Admin/Services/AdminLoginLogService.php | 2 +- 6 files changed, 42 insertions(+), 17 deletions(-) diff --git a/README.en.md b/README.en.md index 8cd936e..9097085 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 92ed5e6..19737e2 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 34b9eb9..6e9ac9a 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 9db7a50..ce3f389 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 7e8f233..52ae544 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 59b9439..c238df0 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'); }, -- Gitee