From: Mike Bayer Date: Mon, 10 Mar 2008 00:59:51 +0000 (+0000) Subject: - relation() can accept a callable for its first argument, X-Git-Tag: rel_0_4_4~17 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9d3216d3f306f5b1be71bd164b60b9ef667a528e;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - relation() can accept a callable for its first argument, which returns the class to be related. This is in place to assist declarative packages to define relations without classes yet being in place. --- diff --git a/CHANGES b/CHANGES index 32355b56ee..d905bbc6de 100644 --- a/CHANGES +++ b/CHANGES @@ -77,7 +77,12 @@ CHANGES - deprecated Query methods apply_sum(), apply_max(), apply_min(), apply_avg(). Better methodologies are coming.... - + + - relation() can accept a callable for its first argument, + which returns the class to be related. This is in place + to assist declarative packages to define relations without + classes yet being in place. + - Added a new "higher level" operator called "of_type()": used in join() as well as with any() and has(), qualifies the subclass which will be used in filter criterion, e.g.: diff --git a/lib/sqlalchemy/orm/properties.py b/lib/sqlalchemy/orm/properties.py index 8e17157da7..79c4ba63b0 100644 --- a/lib/sqlalchemy/orm/properties.py +++ b/lib/sqlalchemy/orm/properties.py @@ -468,6 +468,9 @@ class PropertyLoader(StrategizedProperty): self.mapper = mapper.class_mapper(self.argument, entity_name=self.entity_name, compile=False) elif isinstance(self.argument, mapper.Mapper): self.mapper = self.argument + elif callable(self.argument): + # accept a callable to suit various deferred-configurational schemes + self.mapper = mapper.class_mapper(self.argument(), entity_name=self.entity_name, compile=False) else: raise exceptions.ArgumentError("relation '%s' expects a class or a mapper argument (received: %s)" % (self.key, type(self.argument)))