变更
This commit is contained in:
+1
-1
@@ -21,7 +21,7 @@ class HasCount extends HasBase
|
|||||||
public function get(): array|ModelInterface|null
|
public function get(): array|ModelInterface|null
|
||||||
{
|
{
|
||||||
$relation = Kiri::getDi()->get(Relation::class);
|
$relation = Kiri::getDi()->get(Relation::class);
|
||||||
return $relation->count($this->name);
|
return $relation->getQuery($this->name)->count();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -29,6 +29,6 @@ class HasMany extends HasBase
|
|||||||
public function get(): array|Collection|null
|
public function get(): array|Collection|null
|
||||||
{
|
{
|
||||||
$relation = Kiri::getDi()->get(Relation::class);
|
$relation = Kiri::getDi()->get(Relation::class);
|
||||||
return $relation->get($this->name);
|
return $relation->getQuery($this->name)->get();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -28,6 +28,6 @@ class HasOne extends HasBase
|
|||||||
public function get(): array|ModelInterface|null
|
public function get(): array|ModelInterface|null
|
||||||
{
|
{
|
||||||
$relation = Kiri::getDi()->get(Relation::class);
|
$relation = Kiri::getDi()->get(Relation::class);
|
||||||
return $relation->first($this->name);
|
return $relation->getQuery($this->name)->first();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-3
@@ -28,7 +28,7 @@ abstract class HasBase implements \Database\Traits\Relation
|
|||||||
{
|
{
|
||||||
|
|
||||||
/** @var ModelInterface|Collection */
|
/** @var ModelInterface|Collection */
|
||||||
protected Collection|ModelInterface $data;
|
protected mixed $data = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var ModelInterface
|
* @var ModelInterface
|
||||||
@@ -37,7 +37,7 @@ abstract class HasBase implements \Database\Traits\Relation
|
|||||||
|
|
||||||
|
|
||||||
protected mixed $value = 0;
|
protected mixed $value = 0;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* HasBase constructor.
|
* HasBase constructor.
|
||||||
@@ -71,6 +71,9 @@ abstract class HasBase implements \Database\Traits\Relation
|
|||||||
*/
|
*/
|
||||||
public function __get($name): mixed
|
public function __get($name): mixed
|
||||||
{
|
{
|
||||||
return $this->get();
|
if ($this->data === null) {
|
||||||
|
$this->data = $this->get();
|
||||||
|
}
|
||||||
|
return $this->data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user