def formalize(self):
source_class = self.source_link.to_metaclass<EOL>target_class = self.target_link.to_metaclass<EOL>source_class.referential_attributes |= set(self.source_keys)<EOL>target_class.identifying_attributes |= set(self.target_keys)<EOL>def fget(inst, ref_name, alt_prop):<EOL><INDENT>other_inst = self.target_link.navigate_one(inst)<EOL>if other_inst is None and alt_prop:<EOL><INDENT>return alt_prop.fget(inst)<EOL><DEDENT>return getattr(other_inst, ref_name, None)<EOL><DEDENT>def fset(inst, value, name, ref_name, alt_prop):<EOL><INDENT>kind = get_metaclass(inst).kind<EOL>raise MetaException('<STR_LIT>''<STR_LIT>'% (kind, name))<EOL><DEDENT>for ref_key, primary_key in zip(self.source_keys, self.target_keys):<EOL><INDENT>prop = getattr(source_class.clazz, ref_key, None)<EOL>prop = property(partial(fget, ref_name=primary_key, alt_prop=prop), <EOL>partial(fset, name=ref_key, ref_name=primary_key, alt_prop=prop))<EOL>setattr(source_class.clazz, ref_key, prop)<EOL><DEDENT>
Formalize the association and expose referential attributes
on instances.