How do I select specific columns from a query.
For example, just the User name and size of a photo from:
class User(Base):
__tablename__ = 'user'
user_id = Column(String, primary_key = True, unique = True)
real_name = Column(String, nullable = True)
class Photo(Base):
__tablename__ = 'photo'
url = Column(String, primary_key = True, unique = True)
size = Column(Integer, nullable = False)
ts_taken = Column(DateTime, nullable = True)
user_id = Column(String, ForeignKey('user.user_id'))
user = relationship(User, backref='photos')
I can use:
s.query(Photo).join(User.photo).all()
or maybe, if I want all the photos of a specfic user:
s.query(Photo).join(User.photo).filter(User.user_id == '1234').all()
But how do I make it return just the User.real_name and the size?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…