变更
This commit is contained in:
@@ -13,22 +13,6 @@ use Exception;
|
||||
class HasCount extends HasBase
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $arguments
|
||||
* @return static
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (!method_exists($this, $name)) {
|
||||
$key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value;
|
||||
$this->_relation->getQuery($key)->$name(...$arguments);
|
||||
} else {
|
||||
call_user_func([$this, $name], ...$arguments);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null|ModelInterface
|
||||
* @throws Exception
|
||||
|
||||
+1
-17
@@ -21,22 +21,6 @@ use Exception;
|
||||
class HasMany extends HasBase
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $arguments
|
||||
* @return static
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (!method_exists($this, $name)) {
|
||||
$key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value;
|
||||
$this->_relation->getQuery($key)->$name(...$arguments);
|
||||
} else {
|
||||
call_user_func([$this, $name], ...$arguments);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null|Collection
|
||||
* @throws Exception
|
||||
@@ -44,6 +28,6 @@ class HasMany extends HasBase
|
||||
public function get(): array|Collection|null
|
||||
{
|
||||
$key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value;
|
||||
return $this->_relation->get($key);
|
||||
return $this->_relation->get(md5($key));
|
||||
}
|
||||
}
|
||||
|
||||
+1
-17
@@ -20,22 +20,6 @@ use Exception;
|
||||
class HasOne extends HasBase
|
||||
{
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $arguments
|
||||
* @return static
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (!method_exists($this, $name)) {
|
||||
$key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value;
|
||||
$this->_relation->getQuery($key)->$name(...$arguments);
|
||||
} else {
|
||||
call_user_func([$this, $name], ...$arguments);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array|null|ModelInterface
|
||||
* @throws Exception
|
||||
@@ -43,6 +27,6 @@ class HasOne extends HasBase
|
||||
public function get(): array|ModelInterface|null
|
||||
{
|
||||
$key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value;
|
||||
return $this->_relation->first($key);
|
||||
return $this->_relation->first(md5($key));
|
||||
}
|
||||
}
|
||||
|
||||
+20
-3
@@ -31,7 +31,7 @@ abstract class HasBase implements \Database\Traits\Relation
|
||||
*/
|
||||
protected mixed $model;
|
||||
|
||||
protected mixed $value = [];
|
||||
protected mixed $value = 0;
|
||||
|
||||
|
||||
/** @var Relation $_relation */
|
||||
@@ -60,11 +60,28 @@ abstract class HasBase implements \Database\Traits\Relation
|
||||
$_model = $model::query()->where(['t1.' . $primaryId => $value]);
|
||||
}
|
||||
|
||||
$this->value = is_array($value) ? json_encode($value,JSON_UNESCAPED_UNICODE) : $value;
|
||||
$this->_relation = $relation->bindIdentification($model . '_' . $primaryId . '_' . $this->value, $_model);
|
||||
$this->value = is_array($value) ? json_encode($value, JSON_UNESCAPED_UNICODE) : $value;
|
||||
$this->_relation = $relation->bindIdentification(md5($model . '_' . $primaryId . '_' . $this->value), $_model);
|
||||
$this->model = $model;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
* @param $arguments
|
||||
* @return static
|
||||
*/
|
||||
public function __call($name, $arguments)
|
||||
{
|
||||
if (!method_exists($this, $name)) {
|
||||
$key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value;
|
||||
var_dump($this->model, $this->primaryId, $this->value);
|
||||
$this->_relation->getQuery(md5($key))->$name(...$arguments);
|
||||
} else {
|
||||
call_user_func([$this, $name], ...$arguments);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $name
|
||||
|
||||
Reference in New Issue
Block a user