I have a couple of simple models that look something like this:
class StoreImage(Base):
imagepath = Column(Text, nullable=False)
store_id = Column(Integer, ForeignKey('store.id'), nullable=False)
store = relationship('Store')
class Store(Base):
status = Column(Enum('published', 'verify', 'no_position',
name='store_status'),
nullable=False, default='verify')
type = Column(Enum('physical', 'web', name='store_type'),
nullable=False, default='physical')
name = Column(Text, nullable=False)
street = Column(Text)
postal_code = Column(Text)
city = Column(Text)
country = Column(Text)
phone_number = Column(Text)
email = Column(Text)
website = Column(Text)
location = Column(Geometry(geometry_type='POINT', srid=4326))
is_flagship = Column(Boolean, default=False)
images = relationship(StoreImage)
Now what I want to do is query like this:
q = Store.query.filter(Store.is_flagship == True).with_entities(
Store.id,
Store.status,
Store.slug,
Store.type,
Store.name,
Store.street,
Store.postal_code,
Store.city,
Store.country,
Store.phone_number,
Store.email,
Store.website,
func.ST_AsGeoJSON(Store.location).label('location'),
Store.images,
)
The query works, but Store.images
just returns True
for every row. How can I make it return a list of StoreImage
instances/KeyedTuples?
I want to do it this way mainly because I haven't found any other way to make Store.query
return the location in GeoJSON format.
EDIT: One solution for me would be to just return Store
instances from the query and somehow add in location
GeoJSON, either on the declared model or some other way if possible. Don't know how to do this though.