pydantic-odm icon indicating copy to clipboard operation
pydantic-odm copied to clipboard

ReferenceField analogue needed

Open Dogrtt opened this issue 4 years ago • 0 comments

Right now, if you want to store reference to another document, you should create something like this:

class Foo(DBPydanticMixin):
    names: List[str]

    class Config:
        database = 'default'
        collection = 'foo'


class MetaInfo(BaseDBMixin):
    flag: bool = True
    count: int  = 0
    foo: Optional[Foo] = None


class Bar(DBPydanticMixin):
    name: str
    meta: MetaInfo = MetaInfo()

    class Config:
        database = 'default'
        collection = 'bar'

But when you tried to save new Foo in field foo of Embedded model MetaInfo in Bar model you will faced with the fact, that Foo will be saved as separated document in foo collection and also will be duplicated as field of MetaInfo.

Dogrtt avatar May 16 '20 14:05 Dogrtt