xtuml/meta.py
def formalize(self):
        '''
        Formalize the association and expose referential attributes
        on instances.
        '''
        source_class = self.source_link.to_metaclass
        target_class = self.target_link.to_metaclass
        
        source_class.referential_attributes |= set(self.source_keys)
        target_class.identifying_attributes |= set(self.target_keys)

        def fget(inst, ref_name, alt_prop):
            other_inst = self.target_link.navigate_one(inst)
            if other_inst is None and alt_prop:
                return alt_prop.fget(inst)
            
            return getattr(other_inst, ref_name, None)

        def fset(inst, value, name, ref_name, alt_prop):
            kind = get_metaclass(inst).kind
            raise MetaException('%s.%s is a referential attribute '\
                                'and cannot be assigned directly'% (kind, name))
        
            #other_inst = self.target_link.navigate_one(inst)
            #if other_inst is None and alt_prop:
            #    return alt_prop.fset(inst, value)
            #
            #elif other_inst:
            #    return setattr(other_inst, ref_name, value)
        
        for ref_key, primary_key in zip(self.source_keys, self.target_keys):
            prop = getattr(source_class.clazz, ref_key, None)
            prop = property(partial(fget, ref_name=primary_key, alt_prop=prop), 
                            partial(fset, name=ref_key, ref_name=primary_key, alt_prop=prop))
            setattr(source_class.clazz, ref_key, prop)
def formalize(self):
        '''
        Formalize the association and expose referential attributes
        on instances.
        '''
        source_class = self.source_link.to_metaclass
        target_class = self.target_link.to_metaclass
        
        source_class.referential_attributes |= set(self.source_keys)
        target_class.identifying_attributes |= set(self.target_keys)

        def fget(inst, ref_name, alt_prop):
            other_inst = self.target_link.navigate_one(inst)
            if other_inst is None and alt_prop:
                return alt_prop.fget(inst)
            
            return getattr(other_inst, ref_name, None)

        def fset(inst, value, name, ref_name, alt_prop):
            kind = get_metaclass(inst).kind
            raise MetaException('%s.%s is a referential attribute '\
                                'and cannot be assigned directly'% (kind, name))
        
            #other_inst = self.target_link.navigate_one(inst)
            #if other_inst is None and alt_prop:
            #    return alt_prop.fset(inst, value)
            #
            #elif other_inst:
            #    return setattr(other_inst, ref_name, value)
        
        for ref_key, primary_key in zip(self.source_keys, self.target_keys):
            prop = getattr(source_class.clazz, ref_key, None)
            prop = property(partial(fget, ref_name=primary_key, alt_prop=prop), 
                            partial(fset, name=ref_key, ref_name=primary_key, alt_prop=prop))
            setattr(source_class.clazz, ref_key, prop)
def formalize ( self ) : source_class = self . source_link . to_metaclass target_class = self . target_link . to_metaclass source_class . referential_attributes |= set ( self . source_keys ) target_class . identifying_attributes |= set ( self . target_keys ) def fget ( inst , ref_name , alt_prop ) : other_inst = self . target_link . navigate_one ( inst ) if other_inst is None and alt_prop : return alt_prop . fget ( inst ) return getattr ( other_inst , ref_name , None ) def fset ( inst , value , name , ref_name , alt_prop ) : kind = get_metaclass ( inst ) . kind raise MetaException ( '%s.%s is a referential attribute ' 'and cannot be assigned directly' % ( kind , name ) ) #other_inst = self.target_link.navigate_one(inst) #if other_inst is None and alt_prop: #    return alt_prop.fset(inst, value) # #elif other_inst: #    return setattr(other_inst, ref_name, value) for ref_key , primary_key in zip ( self . source_keys , self . target_keys ) : prop = getattr ( source_class . clazz , ref_key , None ) prop = property ( partial ( fget , ref_name = primary_key , alt_prop = prop ) , partial ( fset , name = ref_key , ref_name = primary_key , alt_prop = prop ) ) setattr ( source_class . clazz , ref_key , prop )
Formalize the association and expose referential attributes
        on instances.
Formalize the association and expose referential attributes on instances .