-
Notifications
You must be signed in to change notification settings - Fork 58
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using multi_joined with response object in object #52
Comments
Could you please also provide the SQLAlchemy table definitions and the exact code that generated this output? Plus the fastcrud version. |
This is my table class plan(Base):
__tablename__ = "plan"
id: Mapped[int] = mapped_column("id", autoincrement=True, nullable=False, unique=True, primary_key=True, init=False)
title: Mapped[str] = mapped_column(String(30))
template_id: Mapped[int] = mapped_column(ForeignKey("encrypt_template.id"))
description: Mapped[str|None] = mapped_column(String, default=None)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default_factory=lambda: datetime.now(UTC))
created_by: Mapped[str | None] = mapped_column(String,default=None)
updated_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), default=None)
updated_by: Mapped[str| None] = mapped_column(String, default=None)
deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), default=None)
deleted_by: Mapped[str| None] = mapped_column(String, default=None)
is_deleted: Mapped[bool] = mapped_column(default=False, index=True) class EncryptTemplate(Base):
__tablename__ = "encrypt_template"
id: Mapped[int] = mapped_column("id", autoincrement=True, nullable=False, unique=True, primary_key=True, init=False)
title: Mapped[str] = mapped_column(String)
description: Mapped[str] = mapped_column(String)
created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), default_factory=lambda: datetime.now(UTC))
created_by: Mapped[str | None] = mapped_column(String,default=None)
updated_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), default=None)
updated_by: Mapped[str| None] = mapped_column(String, default=None)
deleted_at: Mapped[datetime | None] = mapped_column(DateTime(timezone=True), default=None)
deleted_by: Mapped[str| None] = mapped_column(String, default=None)
is_deleted: Mapped[bool] = mapped_column(default=False, index=True) |
@igorbenav How can i fix this |
Hey, @vnlebaoduy, which version of fastcrud? Please also show exactly the |
@igorbenav i'm using fastcrud = "^0.11.0" . This is my code and schema: @router.get("/plan", response_model=PaginatedListResponse[PlanJoinRead])
async def get_plan(
request: Request, db: Annotated[AsyncSession, Depends(async_get_db)], page: int = 1, items_per_page: int = 10
) -> dict:
plan_data = await crud_plan.get_multi_joined(db=db,
join_model=EncryptTemplate,
join_prefix="template_",
schema_to_select=PlanJoinRead,
join_schema_to_select=EncryptTemplateRead,
return_as_model=True,
page=page,
items_per_page=items_per_page,
)
print(plan_data)
response: dict[str, Any] = paginated_response(crud_data=plan_data, page=page, items_per_page=items_per_page)
return response This is schema class AirforcePlanJoinRead(BaseModel):
id: int
title: str
top_score: str
template_id: int
is_finished: bool
description: Optional[str] = None
created_at: datetime
created_by: Optional[str] = None |
Ok, I understand now. For the current implementation of |
What's great about the library is you should be able to override methods of either FastCRUD or the EndpointCreator to achieve what you need. It's much easier to adjust it to your needs than to design a complete architecture to handle all important cases in elagant way. Nevertheless this feature seems really important to have. Do you have any roadmap on the mentioned "next version" @igorbenav ? |
I'll change stuff and it should be released over the weekend, there are a few other changes and I need to write the documentation for them as well. |
@igorbenav I have more a question about get multi_joined. When i joined 2 table many to one. I can't not create response object in object. Example: I only create like that
This is response that i want
Please help me :(
The text was updated successfully, but these errors were encountered: