Compare commits

...

3 Commits

Author SHA1 Message Date
as2252258 e5453807f2 eee 2024-09-05 15:42:24 +08:00
as2252258 5a6f6da70a eee 2024-09-02 12:12:39 +08:00
as2252258 beb48f41d2 eee 2024-08-27 11:19:22 +08:00
3 changed files with 51 additions and 7 deletions
+43 -1
View File
@@ -73,6 +73,48 @@ class ActiveQuery extends QueryTrait implements ISqlBuilder
}
/**
* @param string $column
* @param int|float $amount
* @return bool
*/
public function increment(string $column, int|float $amount = 1): bool
{
return (bool)$this->buildCommand($this->builder->mathematics([$column => $amount]))->exec();
}
/**
* @param array $attributes
* @return bool
*/
public function increments(array $attributes): bool
{
return (bool)$this->buildCommand($this->builder->mathematics($attributes))->exec();
}
/**
* @param string $column
* @param int|float $amount
* @return bool
*/
public function decrement(string $column, int|float $amount = 1): bool
{
return (bool)$this->buildCommand($this->builder->mathematics([$column => $amount], '-'))->exec();
}
/**
* @param array $attributes
* @return bool
*/
public function decrements(array $attributes): bool
{
return (bool)$this->buildCommand($this->builder->mathematics($attributes, '-'))->exec();
}
/**
* @throws
*/
@@ -95,7 +137,7 @@ class ActiveQuery extends QueryTrait implements ISqlBuilder
return;
}
if (Context::inCoroutine()) {
Coroutine::create(fn() => $closure($data));
Coroutine::create(fn () => $closure($data));
} else {
call_user_func($closure, $data);
}
+6 -4
View File
@@ -1,4 +1,5 @@
<?php /** @noinspection ALL */
<?php
/** @noinspection ALL */
/**
* Created by PhpStorm.
* User: whwyy
@@ -222,8 +223,8 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
*/
public function getPrimaryValue(): ?int
{
if ($this->hasPrimary()) {
return (int)$this->_oldAttributes[$this->getPrimary()] ?? null;
if ($this->hasPrimary() && isset($this->_oldAttributes[$this->getPrimary()])) {
return (int)$this->_oldAttributes[$this->getPrimary()];
} else {
return null;
}
@@ -234,8 +235,9 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
* @return Model|null
* @throws
*/
public static function findOne(int|string|array $param): ?static
public static function findOne(int|string|array|null $param): ?static
{
if (empty($param)) return null;
$model = static::instance();
$query = new ActiveQuery($model);
$query->from($model->getTable())->alias('t1');
+2 -2
View File
@@ -18,10 +18,10 @@ interface ModelInterface
{
/**
* @param array|string|int $param
* @param array|string|int|null $param
* @return ModelInterface|null
*/
public static function findOne(array|string|int $param): ?static;
public static function findOne(array|string|int|null $param): ?static;
/**