【发布时间】:2019-08-17 05:39:10
【问题描述】:
我正在努力弄清楚如何根据相当常见的表格 postgis 模式在 Peewee 中加入表格。我需要加入一个基于 postgis 函数(st_contains)的表。我想它看起来像:
Station.select().join(Location, on=fn.ST_Intersects(Station.geom, Location.geom)).where(Location.name == 'Ravenswood')
如果支持,上述查询将返回名为 Ravenswood 的位置中的所有站点。等效的 SQL 将是:
SELECT station.name, station.district, station.line
FROM station INNER JOIN location ON ST_Intersects(station.geom, loc.geom)
WHERE location.name = 'Ravenswood';
不幸的是,我的实验似乎都以这个简短的回溯结束:
File "/Users/j.../python2.7/site-packages/peewee.py", line 1555, in generate_joins
left_field = field.to_field
AttributeError: 'NoneType' object has no attribute 'to_field'
peewee 支持这个吗?我在文档中找不到它。
【问题讨论】:
-
Peewee 的连接生成检查表达式但不检查函数调用。我已在 61034c569e9679832327332aee0348a57a2b990c 中修复了此错误。如果您使用 peewee master,您现在应该可以运行查询了。