octabytes / FireO

Google Cloud Firestore modern and simplest convenient ORM package in Python. FireO is specifically designed for the Google's Firestore
https://fireo.octabyte.io
Apache License 2.0
250 stars 30 forks source link

ReferenceFields support for TypedModel #217

Closed milanmitrovic closed 11 months ago

milanmitrovic commented 1 year ago

I noticed that there is no reference field support for TypedModels. Is there a plan to add this functionality? Should I use some kind of workaround?

ADR-007 commented 1 year ago

Hi! I don't work with Firestore anymore, and I am unsure if I will have time for this... In general, you need to add a new FieldResolver to add support for the new type.

Something like this:

class CustomAnnotationResolver(AnnotationResolver):
    resolvers = [*AnnotationResolver.resolvers, MyCustomTypeFieldResolver]

class MyModel(TypedModel):
   class Meta:
       annotation_resolver_cls = CustomAnnotationResolver

   my_field: MyCustomType

You can find some examples of the resolvers here: src/fireo/typedmodels/resolver.py

milanmitrovic commented 11 months ago

Thank you. I made it work along those lines.