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

Model to have a ReferenceField to itself #204

Open 0xCaponte opened 1 year ago

0xCaponte commented 1 year ago

Is it possible for a Model to have a ReferenceField to itself?

I am trying to cover these use cases:

This logic is already in Firestore and I can query it just fine but when writing the models I can not get it to work due to circular imports.

I could work around this by just storing the documents IDs and then manually getting them when needed but it seems to me that the use cases listed above are not too unusual so I have the feeling that I might be missing something basic here.

My current Classes:


class Users(Model):
    name = TextField()
    createdBy  = ReferenceField(Users) 
    belongsTo = ReferenceField(Departments)

class Departments(Model):
    name = TextField()
    createdBy  = ReferenceField(Users) 
    belongsTo = ReferenceField(Departments)

Thank you in advance for your answer and for the project itself. I am just starting with it but it looks very promising.

ADR-007 commented 1 year ago

Hi 0xCaponte! Thank you for your writing!

It looks like this feature is not implemented. But it can be done by changing the ReferenceField implementation. Feel free to make a PR.

I generally like to contribute to this project, but I still have a list of features I use in my project and want to merge with FireO.

Thank you!