Have BelongsToMany inherit constraints from relationship query (Issue #5589)