Skip to content

Commit

Permalink
Update embedded documents (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarsil authored Jul 3, 2024
1 parent 102d06b commit 8d21a7c
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions mongoz/core/db/documents/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,5 @@ class EmbeddedDocument(BaseModel, metaclass=EmbeddedModelMetaClass):
Graphical representation of an Embedded document.
"""

model_config: ClassVar[pydantic.ConfigDict] = pydantic.ConfigDict(arbitrary_types_allowed=True)
__mongoz_fields__: ClassVar[Mapping[str, Type["MongozField"]]]
36 changes: 36 additions & 0 deletions tests/embedded_documents/test_embedded_doc_decimal.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
from typing import List

import pytest

import mongoz
from mongoz import Document, EmbeddedDocument
from tests.conftest import client

pytestmark = pytest.mark.anyio


class Actor(EmbeddedDocument):
name: str = mongoz.String()
price: float = mongoz.Decimal(max_digits=5, decimal_places=2, null=True)


class Movie(Document):
actors: List[Actor] = mongoz.Array(Actor)

class Meta:
registry = client
database = "test_db"


async def test_embedded_model() -> None:
actor = Actor(name="Tom Hanks", price=100.00)

await Movie(
actors=[actor],
name="Saving Private Ryan",
).create()

movie = await Movie.objects.last()

assert movie.actors[0].name == "Tom Hanks"
assert float(str(movie.actors[0].price)) == 100.00

0 comments on commit 8d21a7c

Please sign in to comment.