Correctly pass joins when creating a JoinDependency.

Backport of #14834 to 4-0-stable.

/cc @rafaelfranca