def compile(self, prop): if self.prop: return self.prop = prop mapper = prop.mapper.primary_mapper() if mapper._get_property(self.key, raiseerr=False) is None: pj = self.kwargs.pop('primaryjoin', None) sj = self.kwargs.pop('secondaryjoin', None) parent = prop.parent.primary_mapper() self.kwargs.setdefault('viewonly', prop.viewonly) self.kwargs.setdefault('post_update', prop.post_update) relation = PropertyLoader(parent, prop.secondary, pj, sj, backref=BackRef(prop.key, _prop=prop), is_backref=True, **self.kwargs) mapper._compile_property(self.key, relation); prop._reverse_property = mapper._get_property(self.key) mapper._get_property(self.key)._reverse_property = prop else: raise exceptions.ArgumentError("Error creating backref '%s' on relation '%s': property of that name exists on mapper '%s'" % (self.key, prop, mapper))
def compile(self, prop): if self.prop: return self.prop = prop mapper = prop.mapper.primary_mapper() if mapper._get_property(self.key, raiseerr=False) is None: if prop.secondary: pj = self.kwargs.pop('primaryjoin', prop.secondaryjoin) sj = self.kwargs.pop('secondaryjoin', prop.primaryjoin) else: pj = self.kwargs.pop('primaryjoin', prop.primaryjoin) sj = self.kwargs.pop('secondaryjoin', None) if sj: raise sa_exc.InvalidRequestError( "Can't assign 'secondaryjoin' on a backref against " "a non-secondary relation.") parent = prop.parent.primary_mapper() self.kwargs.setdefault('viewonly', prop.viewonly) self.kwargs.setdefault('post_update', prop.post_update) relation = RelationProperty(parent, prop.secondary, pj, sj, backref=BackRef(prop.key, _prop=prop), **self.kwargs) mapper._configure_property(self.key, relation); prop._add_reverse_property(self.key) else: raise sa_exc.ArgumentError("Error creating backref '%s' on relation '%s': " "property of that name exists on mapper '%s'" % (self.key, prop, mapper))
def compile(self, prop): if self.prop: return self.prop = prop mapper = prop.mapper.primary_mapper() if mapper._get_property(self.key, raiseerr=False) is None: if prop.secondary: pj = self.kwargs.pop("primaryjoin", prop.secondaryjoin) sj = self.kwargs.pop("secondaryjoin", prop.primaryjoin) else: pj = self.kwargs.pop("primaryjoin", prop.primaryjoin) sj = self.kwargs.pop("secondaryjoin", None) if sj: raise sa_exc.InvalidRequestError( "Can't assign 'secondaryjoin' on a backref against " "a non-secondary relation." ) parent = prop.parent.primary_mapper() self.kwargs.setdefault("viewonly", prop.viewonly) self.kwargs.setdefault("post_update", prop.post_update) relation = RelationProperty( parent, prop.secondary, pj, sj, backref=BackRef(prop.key, _prop=prop), _is_backref=True, **self.kwargs ) mapper._compile_property(self.key, relation) prop._reverse_property = mapper._get_property(self.key) mapper._get_property(self.key)._reverse_property = prop else: raise sa_exc.ArgumentError( "Error creating backref '%s' on relation '%s': " "property of that name exists on mapper '%s'" % (self.key, prop, mapper) )