-
Hi, class ChildModel(Base):
__tablename__ = "child"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
# other columns
parent_id: Mapped[int] = mapped_column(ForeignKey("parent.id"))
parent: Mapped["ParentModel"] = relationship(
back_populates="children", lazy="joined"
)
class ParentModel(Base):
__tablename__ = "parent"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str]
# other colums
children: Mapped[List["ChildModel"]] = relationship(back_populates="parent")
class ParentModelDTO(SQLAlchemyDTO[ParentModel]):
config = DTOConfig(exclude={"id", "children.0.parent_id" "children.0.id"})
class ChildModelDTO(SQLAlchemyDTO[ChildModel]):
config = DTOConfig(exclude={"id", "parent_id", "parent"}) In my controller I set the class ParentHandler(Controller):
path = "/parent"
dto = ParentModelDTO
return_dto = ParentModelDTO
@get(path="")
async def get_parents(self, transaction: AsyncSession) -> List[ParentModel]:
query = select(ParentModel).options(selectinload(ParentModel.children))
result = await transaction.execute(query)
return result.scalars().all() I was expecting the resulting json to be outputed without What am I doing wrong? Should I rename those field in my Thanks |
Beta Was this translation helpful? Give feedback.
Answered by
Alc-Alc
Sep 7, 2023
Replies: 1 comment 1 reply
-
Heya, there is a typo here
it must be
|
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
JacobCoffee
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Heya, there is a typo here
it must be