Correctly handle joining scoped associations with table aliases.

Backport of #14154 to 4-0-stable.