Fix error when handle relations