art049 / odmantic

Sync and Async ODM (Object Document Mapper) for MongoDB based on python type hints
http://art049.github.io/odmantic
ISC License
1.06k stars 92 forks source link

Extended Reference Pattern with odmantic #496

Open Spucis opened 1 month ago

Spucis commented 1 month ago

I wanted to implement the Extended Reference Pattern using odmantic, as explained in this mongodb article https://www.mongodb.com/blog/post/building-with-patterns-the-extended-reference-pattern.

I tought that the solution to my problem would have been the Referenced Model. As odmatic's documentations states in the modeling chapter "Another use case where references are useful is for one-to-one/one-to-many relations but when the referenced model has to exist in its own collection, in order to be accessed on its own without any parent model specified."

This seems to be the perfect use case scenario, but i noticed that Reference Model does not permit to retrieve any attribute from the referenced model, except from the objectId (or any primary key i'm guessing).

Am i correct? Or I am missing something?

If I'm correct, wouldn't be a nice feature to be able to use Referenced model to retrieve also other attribute other than the primary key? This will permit to implement the Extended Reference Pattern.

Probably i could user Embedded Models, but then i will lose the possibility to have the check that the Embedded model exist, am i right?

Thanks in advice!