BeanieODM / beanie

Asynchronous Python ODM for MongoDB
http://beanie-odm.dev/
Apache License 2.0
2.02k stars 213 forks source link

Feature request: Support for Optional[List[Link]] relation #300

Closed SamEdwardes closed 1 year ago

SamEdwardes commented 2 years ago

Feature request

Thank you for all of the great work on Beanie @roman-right! I would like to make a feature request. It would be helpful to extend the supported relationship patterns to include:

Optional[List[Link[...]]

Per the docs the currently supported patterns are:

Related issues

rgajason commented 2 years ago

+1

This feature would be helpful for situations where the parent object is created separately from the process to add/remove items to it. For example, a "group" model that links to a list of "users". It is valid for a group to exist and be empty.

roman-right commented 2 years ago

Hi! Thank you for the suggestion. I'll add this soon.

turkic-dev commented 2 years ago

@roman-right When will this feature be added?

I'm using it like this right now, would that be a problem? perm:List[Link[Permission]] = []

SamEdwardes commented 2 years ago

@roman-right When will this feature be added?

I'm using it like this right now, would that be a problem? perm:List[Link[Permission]] = []

I think you will want to use the Field class like this:

from pydantic import Field

perm:List[Link[Permission]] = Field(default_factory=list)