add some bugfix, make relation to itself also work in postgre