def create_prop(self, mapper, key): oldprop = mapper.props[key] if self.defer: prop = DeferredColumnProperty(*oldprop.columns, **self.kwargs) else: prop = ColumnProperty(*oldprop.columns, **self.kwargs) mapper._compile_property(key, prop)
def process_by_key(self, mapper, key): tokens = key.split('.', 1) if len(tokens) > 1: oldprop = mapper.props[tokens[0]] newprop = oldprop.copy() newprop.argument = self.process_by_key(oldprop.mapper.copy(), tokens[1]) mapper._compile_property(tokens[0], newprop) else: self.create_prop(mapper, tokens[0]) return mapper
def create_prop(self, mapper, key): if self.toeager: class_ = EagerLoader elif self.toeager is None: class_ = PropertyLoader else: class_ = LazyLoader oldprop = mapper.props[key] newprop = class_.__new__(class_) newprop.__dict__.update(oldprop.__dict__) newprop.do_init_subclass(key, mapper) mapper._compile_property(key, newprop)
def compile(self, prop): """called by the owning PropertyLoader to set up a backreference on the PropertyLoader's mapper.""" # try to set a LazyLoader on our mapper referencing the parent mapper mapper = prop.mapper.primary_mapper() if not mapper.props.has_key(self.key): pj = self.kwargs.pop('primaryjoin', None) sj = self.kwargs.pop('secondaryjoin', None) # TODO: we are going to have the newly backref'd property create its # primary/secondary join through normal means, and only override if they are # specified to the constructor. think about if this is really going to work # all the way. #if pj is None: # if prop.secondaryjoin is not None: # # if setting up a backref to a many-to-many, reverse the order # # of the "primary" and "secondary" joins # pj = prop.secondaryjoin # sj = prop.primaryjoin # else: # pj = prop.primaryjoin # sj = None lazy = self.kwargs.pop('lazy', True) if lazy: cls = LazyLoader else: cls = EagerLoader # the backref property is set on the primary mapper parent = prop.parent.primary_mapper() relation = cls(parent, prop.secondary, pj, sj, backref=prop.key, is_backref=True, **self.kwargs) mapper._compile_property(self.key, relation) else: # else set one of us as the "backreference" parent = prop.parent.primary_mapper() if parent.class_ is not mapper.props[self.key]._get_target_class(): raise exceptions.ArgumentError( "Backrefs do not match: backref '%s' expects to connect to %s, but found a backref already connected to %s" % (self.key, str(parent.class_), str(mapper.props[self.key].mapper.class_))) if not mapper.props[self.key].is_backref: prop.is_backref = True prop._dependency_processor.is_backref = True
def create_prop(self, mapper, key): kwargs = util.constructor_args(oldprop) mapper._compile_property(key, class_(**kwargs))