Show
Ignore:
Timestamp:
07/07/08 14:55:41 (5 years ago)
Author:
ged
Message:

- Added support for viewonly relationships (OneToMany and OneToOne).

Files:
1 modified

Legend:

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

    r350 r355  
    413413 
    414414        kwargs.update(self.get_prop_kwargs()) 
     415 
    415416        self.property = relation(self.target, **kwargs) 
    416417        self.add_mapper_property(self.name, self.property) 
     
    451452 
    452453    def is_inverse(self, other): 
    453         return other is not self and \ 
     454        # viewonly relationships shouldn't match as inverse of anything (so 
     455        # that no backref is created -- which doesn't make sense in that case) 
     456        viewonly = self.kwargs.get('viewonly', False) or \ 
     457                   other.kwargs.get('viewonly', False) 
     458        return not viewonly and \ 
     459               other is not self and \ 
    454460               self.match_type_of(other) and \ 
    455461               self.entity == other.target and \ 
     
    612618 
    613619    def create_keys(self, pk): 
     620        # When using a viewonly relationship, you are on your own: Elixir 
     621        # doesn't check that a corresponding ManyToOne relationship exists. 
     622        if self.kwargs.get('viewonly', False): 
     623            return 
     624 
    614625        # make sure an inverse relationship exists 
    615626        if self.inverse is None: 
     
    637648            kwargs['remote_side'] = self.inverse.foreign_key 
    638649 
    639         if self.inverse.primaryjoin_clauses: 
    640             kwargs['primaryjoin'] = and_(*self.inverse.primaryjoin_clauses) 
     650        # viewonly relationships do not have any inverse (and they provide  
     651        # their primaryjoin argument manually anyway). 
     652        if not self.kwargs.get('viewonly', False): 
     653            if self.inverse.primaryjoin_clauses: 
     654                kwargs['primaryjoin'] = and_(*self.inverse.primaryjoin_clauses) 
    641655 
    642656        kwargs.update(self.kwargs)