In my Flask + SQLAlchemy application I have - besider others - these two DB tables/models:
class Client(db.Model):
__tablename__ = "clients"
id = Column(Integer, primary_key=True)
client_name = Column(String, nullable=False, unique=True)
information = Column(String)
class ImageDataSet(db.Model):
__tablename__ = "image_data_sets"
id = Column(Integer, primary_key=True)
client_id = Column(Integer, ForeignKey("clients.id"), nullable=False)
client = db.column_property(db.select([Client.client_name]).where(Client.id == client_id))
So in other words I want to have an attribute client
in my model ImageDataSets
, based on the client_id
from the Client
model/table. This works, however, when starting the application I get the following warning for my call to db.column_property
:
SAWarning: implicitly coercing SELECT object to scalar subquery; please use the.scalar_subquery() method to produce a scalar subquery.
Any ideas what I am doing wrong here?
Thanks to Ilja Everilä's comment I solved this by changing the column property to the following:
client = db.column_property(db.select([Client.client_name]).where(Client.id == client_id).scalar_subquery())
Now the warning is gone.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.