eee
This commit is contained in:
+1
-4
@@ -598,10 +598,7 @@ abstract class Model extends Component implements ModelInterface, ArrayAccess, \
|
||||
*/
|
||||
public function getRelation(): ?Relation
|
||||
{
|
||||
if (Context::exists(Relation::class)) {
|
||||
return Context::get(Relation::class);
|
||||
}
|
||||
return Context::set(Relation::class, new Relation());
|
||||
return di(Relation::class);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ class HasCount extends HasBase
|
||||
*/
|
||||
public function get(): array|ModelInterface|null
|
||||
{
|
||||
return Context::get(Relation::class)->get($this->name);
|
||||
return di(Relation::class)->get($this->name);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,6 +29,6 @@ class HasMany extends HasBase
|
||||
*/
|
||||
public function get(): array|Collection|null
|
||||
{
|
||||
return Context::get(Relation::class)->get($this->name);
|
||||
return di(Relation::class)->get($this->name);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -28,6 +28,6 @@ class HasOne extends HasBase
|
||||
*/
|
||||
public function get(): array|ModelInterface|null
|
||||
{
|
||||
return Context::get(Relation::class)->first($this->name);
|
||||
return di(Relation::class)->first($this->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ class Model extends Base\Model
|
||||
throw new Exception("Need join table primary key.");
|
||||
}
|
||||
|
||||
$relation = $this->getRelation();
|
||||
$relation = di(Relation::class);
|
||||
|
||||
$primaryKey = str_replace('\\\\', '_', $modelName) . '_' . $foreignKey . '_' . $value;
|
||||
if (!$relation->hasIdentification($primaryKey)) {
|
||||
@@ -339,7 +339,7 @@ class Model extends Base\Model
|
||||
throw new Exception("Need join table primary key.");
|
||||
}
|
||||
|
||||
$relation = $this->getRelation();
|
||||
$relation = di(Relation::class);
|
||||
|
||||
$primaryKey = str_replace('\\\\', '_', $modelName) . '_' . $foreignKey . '_' . implode('_', $value);
|
||||
if (!$relation->hasIdentification($primaryKey)) {
|
||||
|
||||
+1
-1
@@ -58,7 +58,7 @@ abstract class HasBase implements \Database\Traits\Relation
|
||||
public function __call(string $name, array $arguments)
|
||||
{
|
||||
if ($name !== 'get') {
|
||||
$query = Context::get(Relation::class)->getQuery($this->name);
|
||||
$query = di(Relation::class)->getQuery($this->name);
|
||||
if (is_null($query)) {
|
||||
throw new \Exception('Unknown relation key: ' . $this->name);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user