Support namespaced belongs to

Fixes #2217 as proposed on the comment I've put there
I'm open to suggestions.