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 29 forks source link

Query by reference key not working #78

Closed weiztech closed 3 years ago

weiztech commented 3 years ago
User(Models):
    fields

Address(Models):
    user = ReferenceField(User, auto_load=False)

I checked on firestore the reference field value is key or user.key tried to query like below but not working.

Address.collection.filter(user=user.key).get()

weiztech commented 3 years ago

I found the model missing DocumentReference on filter/query.

tried using firestore directly, on get/query User it always return the DocumentReference, then it can be use to query reference type on Address.

is it possible to get DocumentReference on the query/get User model ?

weiztech commented 3 years ago

found it user_instance._meta._referenceDoc, it would be great if the _reference available on instance class.

but it seems not thread safety to use the property directly, please correct me if I'm wrong.

AxeemHaider commented 3 years ago

Thanks for this effort but I think adding document reference is not good usually when you have to store it and retrieve it back when needed. Mostly when you create cursor it's hard to store doc ref instead of this we have to use the key which is a str easy to store and all most in all cases we are using key to save, update and delete etc.

And I think it is easy to use key you can do it like you want before

Address.collection.filter(user=user.key).get()

I fixed this in new version v.1.3.7

weiztech commented 3 years ago

just check the update and its looks better this way 👍 . Thanks for the fix.