Fix javascript error and refactor relationship filed