Answer the question
In order to leave comments, you need to log in
Which dumper to use for Flask sqlalchemy?
rows = db.session.query(User, UserItem).join(UserItem).filter(User.id == 2).all()
print(rows)
(<models.User object at 0x7fae4f7d09b0>, <models.UserItem object at 0x7fae4f7d0ac8>)
Answer the question
In order to leave comments, you need to log in
You need to define the __repr__ method for the class with which you describe the entity:
An example from the documentation ( docs.sqlalchemy.org/en/rel_0_9/orm/tutorial.html):
from sqlalchemy import Column, Integer, String
>>> class User(Base):
... __tablename__ = 'users'
...
... id = Column(Integer, primary_key=True)
... name = Column(String)
... fullname = Column(String)
... password = Column(String)
...
... def __repr__(self):
... return "<User(name='%s', fullname='%s', password='%s')>" % (
... self.name, self.fullname, self.password)
from sqlalchemy import inspect
...
def __repr__(self):
mapper = inspect(self).mapper
ent = []
for col in mapper.column_attrs:
ent.append("{0}={1}".format(col.key, getattr(self, col.key)))
return "<{0}(".format(self.__class__.__name__) + ", ".join(ent) + ")>"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question