See https://github.com/yiisoft/yii2/commit/64d8af61a64db0b00d498800e1f20e62b4473329#diff-1776bc9373c1dbb0d6e77ba4d8081a81L762
The change is not correct, using ActiveQuery as $modelClass does not make sense. The call should fail if called on a non-relational query (i.e. if primaryModel is null).
Despite it was a bug, it did not affect working code because the viaTable() call on empty primaryModel does not make sense and could be caused only by wrong manual configuration of the ActiveQuery object.
Heh, actually it makes sense. Thanks to failed tests to point that out :)
It makes sense for viaTable() called from other query closure (like this) during lazy loading of relations.
Fixed with commits 025dd072c and b9ee17014
Seems to be OK now
Most helpful comment
Despite it was a bug, it did not affect working code because the
viaTable()call on emptyprimaryModeldoes not make sense and could be caused only by wrong manual configuration of theActiveQueryobject.