Refactor the relation handling and enable it with attach

/to @ritch