@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare (strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\model\concern; |
14 | 14 | |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | public function setRelation(string $name, $value, array $data = []) |
114 | 114 | { |
115 | 115 | // 检测修改器 |
116 | - $method = 'set' . App::parseName($name, 1) . 'Attr'; |
|
116 | + $method = 'set'.App::parseName($name, 1).'Attr'; |
|
117 | 117 | |
118 | 118 | if (method_exists($this, $method)) { |
119 | 119 | $value = $this->$method($value, array_merge($this->data, $data)); |
@@ -312,7 +312,7 @@ discard block |
||
312 | 312 | $value = $this->getOrigin($key); |
313 | 313 | |
314 | 314 | if (!is_null($value)) { |
315 | - throw new Exception('bind attr has exists:' . $key); |
|
315 | + throw new Exception('bind attr has exists:'.$key); |
|
316 | 316 | } |
317 | 317 | |
318 | 318 | $this->set($key, $relation ? $relation->$attr : null); |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | $count = $this->$relation()->relationCount($result, $closure, $aggregate, $field, $name); |
348 | 348 | |
349 | 349 | if (empty($name)) { |
350 | - $name = App::parseName($relation) . '_' . $aggregate; |
|
350 | + $name = App::parseName($relation).'_'.$aggregate; |
|
351 | 351 | } |
352 | 352 | |
353 | 353 | $result->setAttr($name, $count); |
@@ -472,8 +472,8 @@ discard block |
||
472 | 472 | // 记录当前关联信息 |
473 | 473 | $model = $this->parseModel($model); |
474 | 474 | $name = App::parseName(App::classBaseName($model)); |
475 | - $table = $table ?: App::parseName($this->name) . '_' . $name; |
|
476 | - $foreignKey = $foreignKey ?: $name . '_id'; |
|
475 | + $table = $table ?: App::parseName($this->name).'_'.$name; |
|
476 | + $foreignKey = $foreignKey ?: $name.'_id'; |
|
477 | 477 | $localKey = $localKey ?: $this->getForeignKey($this->name); |
478 | 478 | |
479 | 479 | return new BelongsToMany($this, $model, $table, $foreignKey, $localKey); |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | if (is_array($morph)) { |
501 | 501 | list($morphType, $foreignKey) = $morph; |
502 | 502 | } else { |
503 | - $morphType = $morph . '_type'; |
|
504 | - $foreignKey = $morph . '_id'; |
|
503 | + $morphType = $morph.'_type'; |
|
504 | + $foreignKey = $morph.'_id'; |
|
505 | 505 | } |
506 | 506 | |
507 | 507 | $type = $type ?: get_class($this); |
@@ -532,8 +532,8 @@ discard block |
||
532 | 532 | if (is_array($morph)) { |
533 | 533 | list($morphType, $foreignKey) = $morph; |
534 | 534 | } else { |
535 | - $morphType = $morph . '_type'; |
|
536 | - $foreignKey = $morph . '_id'; |
|
535 | + $morphType = $morph.'_type'; |
|
536 | + $foreignKey = $morph.'_id'; |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | return new MorphMany($this, $model, $foreignKey, $morphType, $type); |
@@ -559,8 +559,8 @@ discard block |
||
559 | 559 | if (is_array($morph)) { |
560 | 560 | list($morphType, $foreignKey) = $morph; |
561 | 561 | } else { |
562 | - $morphType = $morph . '_type'; |
|
563 | - $foreignKey = $morph . '_id'; |
|
562 | + $morphType = $morph.'_type'; |
|
563 | + $foreignKey = $morph.'_id'; |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | return new MorphTo($this, $morphType, $foreignKey, $alias, $relation); |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | $name = App::classBaseName($name); |
597 | 597 | } |
598 | 598 | |
599 | - return App::parseName($name) . '_id'; |
|
599 | + return App::parseName($name).'_id'; |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare (strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\model\concern; |
14 | 14 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | return $this->relation[$name]; |
283 | 283 | } |
284 | 284 | |
285 | - throw new InvalidArgumentException('property not exists:' . static::class . '->' . $name); |
|
285 | + throw new InvalidArgumentException('property not exists:'.static::class.'->'.$name); |
|
286 | 286 | } |
287 | 287 | |
288 | 288 | /** |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function getChangedData(): array |
294 | 294 | { |
295 | - $data = $this->force ? $this->data : array_udiff_assoc($this->data, $this->origin, function ($a, $b) { |
|
295 | + $data = $this->force ? $this->data : array_udiff_assoc($this->data, $this->origin, function($a, $b) { |
|
296 | 296 | if ((empty($a) || empty($b)) && $a !== $b) { |
297 | 297 | return 1; |
298 | 298 | } |
@@ -359,7 +359,7 @@ discard block |
||
359 | 359 | $value = $this->autoWriteTimestamp($name); |
360 | 360 | } else { |
361 | 361 | // 检测修改器 |
362 | - $method = 'set' . App::parseName($name, 1) . 'Attr'; |
|
362 | + $method = 'set'.App::parseName($name, 1).'Attr'; |
|
363 | 363 | |
364 | 364 | if (method_exists($this, $method)) { |
365 | 365 | $array = $this->data; |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | { |
483 | 483 | // 检测属性获取器 |
484 | 484 | $fieldName = $this->getRealFieldName($name); |
485 | - $method = 'get' . App::parseName($name, 1) . 'Attr'; |
|
485 | + $method = 'get'.App::parseName($name, 1).'Attr'; |
|
486 | 486 | |
487 | 487 | if (isset($this->withAttr[$fieldName])) { |
488 | 488 | if ($relation) { |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare (strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\model; |
14 | 14 | |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | protected function getRelationQueryFields($fields, string $model) |
141 | 141 | { |
142 | 142 | if (empty($fields) || '*' == $fields) { |
143 | - return $model . '.*'; |
|
143 | + return $model.'.*'; |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | if (is_string($fields)) { |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | |
150 | 150 | foreach ($fields as &$field) { |
151 | 151 | if (false === strpos($field, '.')) { |
152 | - $field = $model . '.' . $field; |
|
152 | + $field = $model.'.'.$field; |
|
153 | 153 | } |
154 | 154 | } |
155 | 155 | |
@@ -160,10 +160,10 @@ discard block |
||
160 | 160 | { |
161 | 161 | foreach ($where as $key => &$val) { |
162 | 162 | if (is_string($key)) { |
163 | - $where[] = [false === strpos($key, '.') ? $relation . '.' . $key : $key, '=', $val]; |
|
163 | + $where[] = [false === strpos($key, '.') ? $relation.'.'.$key : $key, '=', $val]; |
|
164 | 164 | unset($where[$key]); |
165 | 165 | } elseif (isset($val[0]) && false === strpos($val[0], '.')) { |
166 | - $val[0] = $relation . '.' . $val[0]; |
|
166 | + $val[0] = $relation.'.'.$val[0]; |
|
167 | 167 | } |
168 | 168 | } |
169 | 169 | } |
@@ -237,6 +237,6 @@ discard block |
||
237 | 237 | return $result === $this->query ? $this : $result; |
238 | 238 | } |
239 | 239 | |
240 | - throw new Exception('method not exists:' . __CLASS__ . '->' . $method); |
|
240 | + throw new Exception('method not exists:'.__CLASS__.'->'.$method); |
|
241 | 241 | } |
242 | 242 | } |
@@ -91,9 +91,9 @@ discard block |
||
91 | 91 | $query->via($joinAlias); |
92 | 92 | |
93 | 93 | if ($this instanceof BelongsTo) { |
94 | - $joinOn = $name . '.' . $this->foreignKey . '=' . $joinAlias . '.' . $this->localKey; |
|
94 | + $joinOn = $name.'.'.$this->foreignKey.'='.$joinAlias.'.'.$this->localKey; |
|
95 | 95 | } else { |
96 | - $joinOn = $name . '.' . $this->localKey . '=' . $joinAlias . '.' . $this->foreignKey; |
|
96 | + $joinOn = $name.'.'.$this->localKey.'='.$joinAlias.'.'.$this->foreignKey; |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | if ($closure) { |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | } |
107 | 107 | |
108 | 108 | $query->join([$joinTable => $joinAlias], $joinOn, $joinType) |
109 | - ->tableField($field, $joinTable, $joinAlias, $relation . '__'); |
|
109 | + ->tableField($field, $joinTable, $joinAlias, $relation.'__'); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | $value = $result->getOrigin($key); |
276 | 276 | |
277 | 277 | if (!is_null($value)) { |
278 | - throw new Exception('bind attr has exists:' . $key); |
|
278 | + throw new Exception('bind attr has exists:'.$key); |
|
279 | 279 | } |
280 | 280 | |
281 | 281 | $result->setAttr($key, $model ? $model->$attr : null); |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | // 关联查询 |
160 | 160 | $pk = $this->parent->getPk(); |
161 | 161 | |
162 | - $condition = ['pivot.' . $localKey, '=', $this->parent->$pk]; |
|
162 | + $condition = ['pivot.'.$localKey, '=', $this->parent->$pk]; |
|
163 | 163 | |
164 | 164 | return $this->belongsToManyQuery($foreignKey, $localKey, [$condition]); |
165 | 165 | } |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | */ |
295 | 295 | public function wherePivot($field, $op = null, $condition = null) |
296 | 296 | { |
297 | - $this->query->where('pivot.' . $field, $op, $condition); |
|
297 | + $this->query->where('pivot.'.$field, $op, $condition); |
|
298 | 298 | return $this; |
299 | 299 | } |
300 | 300 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | if (!empty($range)) { |
324 | 324 | // 查询关联数据 |
325 | 325 | $data = $this->eagerlyManyToMany([ |
326 | - ['pivot.' . $localKey, 'in', $range], |
|
326 | + ['pivot.'.$localKey, 'in', $range], |
|
327 | 327 | ], $relation, $subRelation, $closure); |
328 | 328 | |
329 | 329 | // 关联属性名 |
@@ -357,7 +357,7 @@ discard block |
||
357 | 357 | $pk = $result->$pk; |
358 | 358 | // 查询管理数据 |
359 | 359 | $data = $this->eagerlyManyToMany([ |
360 | - ['pivot.' . $this->localKey, '=', $pk], |
|
360 | + ['pivot.'.$this->localKey, '=', $pk], |
|
361 | 361 | ], $relation, $subRelation, $closure); |
362 | 362 | |
363 | 363 | // 关联数据封装 |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | } |
395 | 395 | |
396 | 396 | return $this->belongsToManyQuery($this->foreignKey, $this->localKey, [ |
397 | - ['pivot.' . $this->localKey, '=', $pk], |
|
397 | + ['pivot.'.$this->localKey, '=', $pk], |
|
398 | 398 | ])->$aggregate($field); |
399 | 399 | } |
400 | 400 | |
@@ -415,7 +415,7 @@ discard block |
||
415 | 415 | |
416 | 416 | return $this->belongsToManyQuery($this->foreignKey, $this->localKey, [ |
417 | 417 | [ |
418 | - 'pivot.' . $this->localKey, 'exp', new Raw('=' . $this->parent->db(false)->getTable() . '.' . $this->parent->getPk()), |
|
418 | + 'pivot.'.$this->localKey, 'exp', new Raw('='.$this->parent->db(false)->getTable().'.'.$this->parent->getPk()), |
|
419 | 419 | ], |
420 | 420 | ])->fetchSql()->$aggregate($field); |
421 | 421 | } |
@@ -493,7 +493,7 @@ discard block |
||
493 | 493 | |
494 | 494 | if (empty($this->baseQuery)) { |
495 | 495 | $relationFk = $this->query->getPk(); |
496 | - $query->join([$table => 'pivot'], 'pivot.' . $foreignKey . '=' . $tableName . '.' . $relationFk) |
|
496 | + $query->join([$table => 'pivot'], 'pivot.'.$foreignKey.'='.$tableName.'.'.$relationFk) |
|
497 | 497 | ->where($condition); |
498 | 498 | } |
499 | 499 | |
@@ -715,8 +715,8 @@ discard block |
||
715 | 715 | $table = $this->pivot->getTable(); |
716 | 716 | |
717 | 717 | $this->query |
718 | - ->join([$table => 'pivot'], 'pivot.' . $this->foreignKey . '=' . $this->query->getTable() . '.' . $this->query->getPk()) |
|
719 | - ->where('pivot.' . $this->localKey, $this->parent->$pk); |
|
718 | + ->join([$table => 'pivot'], 'pivot.'.$this->foreignKey.'='.$this->query->getTable().'.'.$this->query->getPk()) |
|
719 | + ->where('pivot.'.$this->localKey, $this->parent->$pk); |
|
720 | 720 | $this->baseQuery = true; |
721 | 721 | } |
722 | 722 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | // +---------------------------------------------------------------------- |
9 | 9 | // | Author: liu21st <[email protected]> |
10 | 10 | // +---------------------------------------------------------------------- |
11 | -declare (strict_types = 1); |
|
11 | +declare(strict_types=1); |
|
12 | 12 | |
13 | 13 | namespace think\model\relation; |
14 | 14 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | } |
89 | 89 | |
90 | 90 | return $this->query |
91 | - ->whereExp($this->foreignKey, '=' . $this->parent->getTable() . '.' . $this->localKey) |
|
91 | + ->whereExp($this->foreignKey, '='.$this->parent->getTable().'.'.$this->localKey) |
|
92 | 92 | ->fetchSql() |
93 | 93 | ->$aggregate($field); |
94 | 94 | } |
@@ -139,10 +139,10 @@ discard block |
||
139 | 139 | |
140 | 140 | return $this->parent->db() |
141 | 141 | ->alias($model) |
142 | - ->whereExists(function ($query) use ($table, $model, $relation, $localKey, $foreignKey) { |
|
142 | + ->whereExists(function($query) use ($table, $model, $relation, $localKey, $foreignKey) { |
|
143 | 143 | $query->table([$table => $relation]) |
144 | - ->field($relation . '.' . $foreignKey) |
|
145 | - ->whereExp($model . '.' . $localKey, '=' . $relation . '.' . $foreignKey); |
|
144 | + ->field($relation.'.'.$foreignKey) |
|
145 | + ->whereExp($model.'.'.$localKey, '='.$relation.'.'.$foreignKey); |
|
146 | 146 | }); |
147 | 147 | } |
148 | 148 | |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | return $this->parent->db() |
172 | 172 | ->alias($model) |
173 | 173 | ->field($fields) |
174 | - ->join([$table => $relation], $model . '.' . $this->localKey . '=' . $relation . '.' . $this->foreignKey, $joinType ?: $this->joinType) |
|
174 | + ->join([$table => $relation], $model.'.'.$this->localKey.'='.$relation.'.'.$this->foreignKey, $joinType ?: $this->joinType) |
|
175 | 175 | ->where($where); |
176 | 176 | } |
177 | 177 |
@@ -231,7 +231,7 @@ |
||
231 | 231 | } |
232 | 232 | |
233 | 233 | return $this->query |
234 | - ->whereExp($this->morphKey, '=' . $this->parent->getTable() . '.' . $this->parent->getPk()) |
|
234 | + ->whereExp($this->morphKey, '='.$this->parent->getTable().'.'.$this->parent->getPk()) |
|
235 | 235 | ->where($this->morphType, '=', $this->type) |
236 | 236 | ->fetchSql() |
237 | 237 | ->$aggregate($field); |
@@ -221,7 +221,7 @@ |
||
221 | 221 | // 关联模型 |
222 | 222 | if (!isset($data[$result->$morphKey])) { |
223 | 223 | $relationModel = null; |
224 | - throw new Exception('relation data not exists :' . $this->model); |
|
224 | + throw new Exception('relation data not exists :'.$this->model); |
|
225 | 225 | } else { |
226 | 226 | $relationModel = $data[$result->$morphKey]; |
227 | 227 | $relationModel->setParent(clone $result); |
@@ -107,16 +107,16 @@ discard block |
||
107 | 107 | $relationTable = $relation->getTable(); |
108 | 108 | |
109 | 109 | if ('*' != $id) { |
110 | - $id = $relationTable . '.' . $relation->getPk(); |
|
110 | + $id = $relationTable.'.'.$relation->getPk(); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return $this->parent->db() |
114 | 114 | ->alias($model) |
115 | - ->field($model . '.*') |
|
116 | - ->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) |
|
117 | - ->join($relationTable, $relationTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) |
|
118 | - ->group($relationTable . '.' . $this->throughKey) |
|
119 | - ->having('count(' . $id . ')' . $operator . $count); |
|
115 | + ->field($model.'.*') |
|
116 | + ->join($throughTable, $throughTable.'.'.$this->foreignKey.'='.$model.'.'.$this->localKey) |
|
117 | + ->join($relationTable, $relationTable.'.'.$throughKey.'='.$throughTable.'.'.$this->throughPk) |
|
118 | + ->group($relationTable.'.'.$this->throughKey) |
|
119 | + ->having('count('.$id.')'.$operator.$count); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | /** |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | |
146 | 146 | return $this->parent->db() |
147 | 147 | ->alias($model) |
148 | - ->join($throughTable, $throughTable . '.' . $this->foreignKey . '=' . $model . '.' . $this->localKey) |
|
149 | - ->join($modelTable, $modelTable . '.' . $throughKey . '=' . $throughTable . '.' . $this->throughPk) |
|
150 | - ->group($modelTable . '.' . $this->throughKey) |
|
148 | + ->join($throughTable, $throughTable.'.'.$this->foreignKey.'='.$model.'.'.$this->localKey) |
|
149 | + ->join($modelTable, $modelTable.'.'.$throughKey.'='.$throughTable.'.'.$this->throughPk) |
|
150 | + ->group($modelTable.'.'.$this->throughKey) |
|
151 | 151 | ->where($where) |
152 | 152 | ->field($fields); |
153 | 153 | } |
@@ -294,14 +294,14 @@ discard block |
||
294 | 294 | $modelTable = $this->parent->getTable(); |
295 | 295 | |
296 | 296 | if (false === strpos($field, '.')) { |
297 | - $field = $alias . '.' . $field; |
|
297 | + $field = $alias.'.'.$field; |
|
298 | 298 | } |
299 | 299 | |
300 | 300 | return $this->query |
301 | 301 | ->alias($alias) |
302 | - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) |
|
303 | - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) |
|
304 | - ->where($throughTable . '.' . $this->foreignKey, $result->$localKey) |
|
302 | + ->join($throughTable, $throughTable.'.'.$pk.'='.$alias.'.'.$throughKey) |
|
303 | + ->join($modelTable, $modelTable.'.'.$this->localKey.'='.$throughTable.'.'.$this->foreignKey) |
|
304 | + ->where($throughTable.'.'.$this->foreignKey, $result->$localKey) |
|
305 | 305 | ->$aggregate($field); |
306 | 306 | } |
307 | 307 | |
@@ -327,14 +327,14 @@ discard block |
||
327 | 327 | $modelTable = $this->parent->getTable(); |
328 | 328 | |
329 | 329 | if (false === strpos($field, '.')) { |
330 | - $field = $alias . '.' . $field; |
|
330 | + $field = $alias.'.'.$field; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | return $this->query |
334 | 334 | ->alias($alias) |
335 | - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) |
|
336 | - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) |
|
337 | - ->whereExp($throughTable . '.' . $this->foreignKey, '=' . $this->parent->getTable() . '.' . $this->localKey) |
|
335 | + ->join($throughTable, $throughTable.'.'.$pk.'='.$alias.'.'.$throughKey) |
|
336 | + ->join($modelTable, $modelTable.'.'.$this->localKey.'='.$throughTable.'.'.$this->foreignKey) |
|
337 | + ->whereExp($throughTable.'.'.$this->foreignKey, '='.$this->parent->getTable().'.'.$this->localKey) |
|
338 | 338 | ->fetchSql() |
339 | 339 | ->$aggregate($field); |
340 | 340 | } |
@@ -357,9 +357,9 @@ discard block |
||
357 | 357 | $this->query |
358 | 358 | ->field($fields) |
359 | 359 | ->alias($alias) |
360 | - ->join($throughTable, $throughTable . '.' . $pk . '=' . $alias . '.' . $throughKey) |
|
361 | - ->join($modelTable, $modelTable . '.' . $this->localKey . '=' . $throughTable . '.' . $this->foreignKey) |
|
362 | - ->where($throughTable . '.' . $this->foreignKey, $this->parent->{$this->localKey}); |
|
360 | + ->join($throughTable, $throughTable.'.'.$pk.'='.$alias.'.'.$throughKey) |
|
361 | + ->join($modelTable, $modelTable.'.'.$this->localKey.'='.$throughTable.'.'.$this->foreignKey) |
|
362 | + ->where($throughTable.'.'.$this->foreignKey, $this->parent->{$this->localKey}); |
|
363 | 363 | |
364 | 364 | $this->baseQuery = true; |
365 | 365 | } |