-
Notifications
You must be signed in to change notification settings - Fork 94
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle references within generics of EmbeddedModel #95
Comments
Hello, yes this is unfortunately not supported yet. A full rework of Reference management is coming soon and this will include this feature 🎉 |
Hi there ! Not exactly the same topic but I managed through Pydantic to solve multi reference problem : get Reference ObjectId into database and full sub Reference data into FastAPI response. This was made through Pydantic custom fields validation. from database.model_utils import ModelObjectId
class Skill(Model):
description:str = Field()
class Student(Model):
class SkillObjectId(ModelObjectId):
_model = Skill
fullname:str = Field()
skills:List[SkillObjectId] # Many References relation. Here we use a specific type to retrieve data on the fly
"""
skills:List[ObjectId] # Many References ODMantic original way
""" Code here : https://github.com/Tatayoyoh/odmantic-many-relations-model I hope it can help :) |
@art049 Is the "full rework of Reference management" still in the works? Any update? |
Bug
When i try to reference other model in EmbeddedModel, i get full document inserted instead of reference to it
Current Behavior
I have these models:
If i try to do this:
I get this in the database:
As you can see full model being inserted into the database with both name and id instead of just reference id to it
However everything is fine if i reference Need model directly:
Database:
Expected behavior
ODMantic should put reference id in EmbeddedModel instead of putting full Model in the field
Environment
python -c "import pydantic.utils; print(pydantic.utils.version_info())
):Additional context
It is also impossible to make reference fields
Optional
or put them in aList
, but I read in the docs that it is planned to make a genericReference[T]
type so it's okThe text was updated successfully, but these errors were encountered: