Fix defining relations as a function, closes #415