无法从FastApi用户和无檐小便帽中的相关文档中获得结果

发布于 2025-02-01 11:42:23 字数 393 浏览 3 评论 0原文

我有几个型号:

class Message(Document):
    phone: str
    message_body: str
    user: Indexed(PydanticObjectId)

    class Settings:
        name = "Message"


class User(BeanieBaseUser[PydanticObjectId]):
    messages: Optional[List[Link[Message]]]

他们使用豆豆链接有关系。 消息模型是自定义模型,用户是FastApi用户的默认模型。

当我将insert()保存在子模型的消息上时,它不会与父母建立关系。使用NULL消息字段返回DICT。 知道有什么错误?

I have a couple of models:

class Message(Document):
    phone: str
    message_body: str
    user: Indexed(PydanticObjectId)

    class Settings:
        name = "Message"


class User(BeanieBaseUser[PydanticObjectId]):
    messages: Optional[List[Link[Message]]]

They have a relationship using Beanie Link.
The Message model is a custom Model and User is the default of FastAPI-Users.

When I save a record with insert() on a Message that is the child model, it does not establish a relationship with the parent. Returning the dict with null messages field.
Any idea what could be the error?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幼儿园老大 2025-02-08 11:42:23

一种方法是使用fetch_link

@app.get("/messages")
async def list_messages(user: User = Depends(current_active_user)):
    await user.fetch_link(User.messages)
    return user.messages

结帐FastApi-Users Creator的响应
https://github.com/github.com/github.com/fastapapi-users/fastapi-users/fastapi-users/fastapi-user用户/讨论/1006#讨论-4101669

One way to do this is with fetch_link

@app.get("/messages")
async def list_messages(user: User = Depends(current_active_user)):
    await user.fetch_link(User.messages)
    return user.messages

Checkout the response from FastAPI-Users creator
https://github.com/fastapi-users/fastapi-users/discussions/1006#discussion-4101669

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文