Replaces commit dfcf037c7. The prvious idea was wrong and broke some tests

This commit is contained in:
SilverFire - Dmitry Naumenko
2019-01-20 13:50:27 +02:00
parent dfcf037c76
commit 025dd072c6

View File

@ -772,11 +772,7 @@ class ActiveQuery extends Query implements ActiveQueryInterface
*/
public function viaTable($tableName, $link, callable $callable = null)
{
if ($this->primaryModel === null) {
throw new InvalidConfigException('The "primaryModel" property is not set. The query must be a relation to use junction tables. You probably need to call hasOne() or hasMany() method first.');
}
$modelClass = get_class($this->primaryModel);
$modelClass = $this->primaryModel ? get_class($this->primaryModel) : $this->modelClass;
$relation = new self($modelClass, [
'from' => [$tableName],
'link' => $link,