Answer the question
In order to leave comments, you need to log in
How to return an instance of a class from the database?
I don't quite understand the moment. How does an ORM query turn into a class:
class User(Base):
__tablename__ = 'users'
id = Column(Integer, primary_key=True)
name = Column(String)
adr = relationship('Address', backref='uuu')
class Address(Base):
__tablename__ = 'addresses'
id = Column(Integer, primary_key=True)
email = Column(String, nullable=False)
# user_id = Column(Integer)
user_id = Column(Integer, ForeignKey('users.id'))
Base.metadata.create_all(engine)
answer = sess.query(User.id, User.name).first() # вот этот момент
answer = sess.query(User.id, Address).first() # тогда что вернется?
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question