pydantic-odm
pydantic-odm copied to clipboard
ReferenceField analogue needed
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
.