diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-02 18:22:50 +0000 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2009-01-02 18:22:50 +0000 |
commit | 50dfbc7e793f1bcfdd22f9cffcefde31f14b186b (patch) | |
tree | 000b7150983c40ec134a31b0d7b3addc0c679b30 /examples/postgis/postgis.py | |
parent | a52a0c43c3d4880df53c46d1fd92fcf8d1a3a758 (diff) | |
download | sqlalchemy-50dfbc7e793f1bcfdd22f9cffcefde31f14b186b.tar.gz |
- Custom comparator classes used in conjunction with
column_property(), relation() etc. can define
new comparison methods on the Comparator, which will
become available via __getattr__() on the
InstrumentedAttribute. In the case of synonym()
or comparable_property(), attributes are resolved first
on the user-defined descriptor, then on the user-defined
comparator.
Diffstat (limited to 'examples/postgis/postgis.py')
-rw-r--r-- | examples/postgis/postgis.py | 13 |
1 files changed, 3 insertions, 10 deletions
diff --git a/examples/postgis/postgis.py b/examples/postgis/postgis.py index 841bce31c..c463cca26 100644 --- a/examples/postgis/postgis.py +++ b/examples/postgis/postgis.py @@ -123,21 +123,14 @@ class GisComparator(ColumnProperty.ColumnComparator): """Intercepts standard Column operators on mapped class attributes and overrides their behavior. - The PropComparator API currently does not allow "custom" - operators to be added, so only those operators which - already exist on Column can be overridden here. Additional - GIS-specific operators can be implemented as standalone - functions. """ def __eq__(self, other): return self.__clause_element__().op('~=')(_to_postgis(other)) -def intersects(x, y): - """An example standalone GIS-specific comparison operator.""" - - return _to_postgis(x).op('&&')(_to_postgis(y)) + def intersects(self, other): + return self.__clause_element__().op('&&')(_to_postgis(other)) class gis_element(object): """Represents a geometry value. @@ -219,7 +212,7 @@ if __name__ == '__main__': assert r1 is r2 is r3 # illustrate the "intersects" operator - print session.query(Road).filter(intersects(Road.road_geom, r1.road_geom)).all() + print session.query(Road).filter(Road.road_geom.intersects(r1.road_geom)).all() # illustrate usage of the "wkt" accessor. this requires a DB # execution to call the AsText() function so we keep this explicit. |