def register_link(self, link):
keys = tuple((ref, link.initial_hook_value) for ref in link.hook_references)<EOL>for k in keys:<EOL><INDENT>if k in self._record_hooks:<EOL><INDENT>link.set_target(target_record=self._record_hooks[k].target_record)<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>for k in keys:<EOL><INDENT>if k in self._table_hooks:<EOL><INDENT>link.set_target(target_table=self._table_hooks[k])<EOL>break<EOL><DEDENT><DEDENT>else:<EOL><INDENT>field_descriptor = link.source_record.get_field_descriptor(link.source_index)<EOL>raise FieldValidationError(<EOL>f"<STR_LIT>"<EOL>f"<STR_LIT>"<EOL>)<EOL><DEDENT><DEDENT>if link.source_record not in self._links_by_source:<EOL><INDENT>self._links_by_source[link.source_record] = set()<EOL><DEDENT>self._links_by_source[link.source_record].add(link)<EOL>if link.target not in self._links_by_target:<EOL><INDENT>self._links_by_target[link.target] = set()<EOL><DEDENT>self._links_by_target[link.target].add(link)<EOL>
source record and index must have been set