I am trying to dynamically populate a field using SqlAlchemy 0.8.4 and GeoAlchemy2 0.2.2. The goal is to designate the Area for the Fund based on the position of the object when it is read from the database. The code is as follows:
class District(Base):
__tablename__ = 'districts'
id = Column(Integer, primary_key=True)
geom = Column('geog', Geometry(geometry_type='POLYGON'), nullable=False)
class Facility(Base):
__tablename__ = 'facilities'
id = Column(Integer, primary_key=True)
pos = Column('geog', Geometry(geometry_type='POINT'), nullable=True)
district = relationship(District,
viewonly=True,
primaryjoin="District.geom.ST_Contains(Facility.pos)",
foreign_keys=[District.id])
But this gives me the following error:
ArgumentError: Could not find matching foreign key columns for the primary join condition 'ST_Contains (districts.geog, facilities.geog)' by Facility.district. Ensure that column references are linked to ForeignKey or ForeignKeyConstraint, or annotated in a state of join with external () annotation
, , .
?