Fix assignment of IDs to multiple relations when one of them is empty an...

...d add test for it (and in general for ID assignment)
OK makes sense. Probably we want to try cleaning these in future develop branch, but not this hotfix.