Correctly pass joins when creating a JoinDependency.

Backport of #14834 to 4-0-stable
Merge pull request #15396 from al2o3cr/issue14834-backport-4-0

Correctly pass joins when creating a JoinDependency.