You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
From my tests I couldn't create document's Field with validation_alias. I could create one with alias e.g.:
class Nested(Document):
some_field: int
class ModelInDB(Document):
main_field: int
nested: Nested
class ModelForQuery(Document):
# this works main field
changed_name: Annotated[int, Field(alias="main_field")
# this doesn't :/
# main_field_changed: Annotated[int, Field(validation_alias="main_field")]
# also would be pretty cool to be able to get into nested field with alias path
# field_in_nested: Annotated[int, Field(validation_alias=AliasPath("nested", "some_field"))]
I have big docs that have many keys, but I don't need to get whole doc, so I would like to be able to create smaller models that change names of some fields, but I sometimes need to access some field from nested dict (that's why usage of AliasPath).
I read that beanie is compatible with pydantic so I thought that validation aliases would just work.
Is there some way to do it another way? I guess I try to create bigger models that have some property fields for easier access, but I don't know if this is the best way to do it.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
From my tests I couldn't create document's Field with validation_alias. I could create one with alias e.g.:
I have big docs that have many keys, but I don't need to get whole doc, so I would like to be able to create smaller models that change names of some fields, but I sometimes need to access some field from nested dict (that's why usage of AliasPath).
I read that beanie is compatible with pydantic so I thought that validation aliases would just work.
Is there some way to do it another way? I guess I try to create bigger models that have some property fields for easier access, but I don't know if this is the best way to do it.
Beta Was this translation helpful? Give feedback.
All reactions