Код: Выделить всё
sqlalchemy.exc.ArgumentError: Query has only expression-based entities; attribute loader options for Mapper[ModelA(modela)] can't be applied here.
Код: Выделить всё
async def get(self, fields):
# parse_fields gets the column and relationship of a SQLAlchemy table model, i.e ModelA.id or ModelA.my_relationship
columns, relationships = self.parse_fields(fields, ModelA)
stmnt = select(*columns)
if len(relationships):
stmnt = stmnt.options(selectinload(*relationships))
result = await self.session.execute(stmnt)
return result.all()
Код: Выделить всё
class ModelA(Base):
__tablename__ = "modela"
name = Column(Text, nullable=True)
bs = relationship("ModelB", back_populates="a", lazy="joined")
class ModelB(Base):
__tablename__ = "modelb"
name = Column(Text, nullable=False)
a_id = Column(BigInteger, ForeignKey("a.id"), nullable=False)
a = relationship("ModelA", back_populates="bs", lazy="joined")
Подробнее здесь: https://stackoverflow.com/questions/782 ... d-entities
Мобильная версия