diff --git a/HasCount.php b/HasCount.php index 33e53e3..c8f354e 100644 --- a/HasCount.php +++ b/HasCount.php @@ -21,7 +21,8 @@ class HasCount extends HasBase public function __call($name, $arguments) { if (!method_exists($this, $name)) { - $this->_relation->getQuery($this->model::className())->$name(...$arguments); + $key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value; + $this->_relation->getQuery($key)->$name(...$arguments); } else { call_user_func([$this, $name], ...$arguments); } diff --git a/HasMany.php b/HasMany.php index 086738c..4e5dc3b 100644 --- a/HasMany.php +++ b/HasMany.php @@ -29,7 +29,8 @@ class HasMany extends HasBase public function __call($name, $arguments) { if (!method_exists($this, $name)) { - $this->_relation->getQuery($this->model::className())->$name(...$arguments); + $key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value; + $this->_relation->getQuery($key)->$name(...$arguments); } else { call_user_func([$this, $name], ...$arguments); } diff --git a/HasOne.php b/HasOne.php index 9fa334a..d2acfb8 100644 --- a/HasOne.php +++ b/HasOne.php @@ -28,7 +28,8 @@ class HasOne extends HasBase public function __call($name, $arguments) { if (!method_exists($this, $name)) { - $this->_relation->getQuery($this->model::className())->$name(...$arguments); + $key = $this->model::className() . '_' . $this->primaryId . '_' . $this->value; + $this->_relation->getQuery($key)->$name(...$arguments); } else { call_user_func([$this, $name], ...$arguments); }