Skip to content
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

[BUG]: Beanie BackLink does not support multiple types #75

Open
mike-pisman opened this issue Oct 17, 2023 · 1 comment
Open

[BUG]: Beanie BackLink does not support multiple types #75

mike-pisman opened this issue Oct 17, 2023 · 1 comment
Labels
bug Something isn't working

Comments

@mike-pisman
Copy link
Member

mike-pisman commented Oct 17, 2023

It is impossible to use multiple types with Beanie BackLink, as a result, the document stores the whole linked document. For example:

class Policy(Document):
    parent_resource: BackLink["Workspace"] | BackLink["Group"] | BackLink["Poll"] = Field(original_field="policies")

When creating new Policy, the parent_resource field stores the whole Workspace/Group document instead, which is undesirable.

The underlying issue has been mentioned in BeanieODM/beanie#746

@mike-pisman mike-pisman added the bug Something isn't working label Oct 17, 2023
mike-pisman added a commit that referenced this issue Oct 17, 2023
A workaround for issue #75, the `parent_resource` was converted to the **Link** type, which is manually populated using create_link() method. Since Beanie cannot/struggles to fetch links of multiple types, two new class methods were added: get_parent_resource() uses link reference to find and return parent document(Workspace/Group/Poll), and get_policy_holder() finds and returns document of policy holder(Account/Group).
@mike-pisman
Copy link
Member Author

A workaround for this issue:

the parent_resource was converted to the Link type, which is manually populated using create_link() method. Since Beanie cannot/struggles to fetch links of multiple types, two new class methods were added: get_parent_resource() uses Link reference to find and return parent document(Workspace/Group/Poll), and get_policy_holder() finds and returns document of policy holder(Account/Group).

For more info, see #76

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant