Show
Ignore:
Timestamp:
07/04/07 14:36:56 (7 years ago)
Author:
ged
Message:

- cleaned up "match_type_of" is relationship: now each relationship do it

itself, instead of having one generic method. I wonder how I didn't think
of this earlier...

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • elixir/trunk/elixir/relationships.py

    r139 r141  
    312312     
    313313    def match_type_of(self, other): 
    314         t1, t2 = type(self), type(other) 
    315      
    316         if t1 is HasAndBelongsToMany: 
    317             return t1 is t2 
    318         elif t1 in (HasOne, HasMany): 
    319             return t2 is BelongsTo 
    320         elif t1 is BelongsTo: 
    321             return t2 in (HasMany, HasOne) 
    322         else: 
    323             return False 
     314        return False 
    324315 
    325316    def is_inverse(self, other): 
     
    357348        super(BelongsTo, self).__init__(entity, name, *args, **kwargs) 
    358349     
     350    def match_type_of(self, other): 
     351        return isinstance(other, (HasMany, HasOne)) 
     352 
    359353    def create_keys(self): 
    360354        ''' 
     
    448442        if self.primaryjoin_clauses: 
    449443            kwargs['primaryjoin'] = and_(*self.primaryjoin_clauses) 
     444 
    450445        kwargs['uselist'] = False 
    451          
     446 
    452447        self.property = relation(self.target, **kwargs) 
    453448        self.entity.mapper.add_property(self.name, self.property) 
     
    456451class HasOne(Relationship): 
    457452    uselist = False 
     453 
     454    def match_type_of(self, other): 
     455        return isinstance(other, BelongsTo) 
    458456 
    459457    def create_keys(self): 
     
    522520        super(HasAndBelongsToMany, self).__init__(entity, name,  
    523521                                                  *args, **kwargs) 
     522 
     523    def match_type_of(self, other): 
     524        return isinstance(other, HasAndBelongsToMany) 
    524525 
    525526    def create_tables(self):