firedantic
firedantic copied to clipboard
Support collection group queries
Currently it is only possible to get a subcollection from a single document:
class UserStats(AsyncSubModel):
id: Optional[str]
purchases: int = 0
class Collection(AsyncSubCollection):
# Can use any properties of the "parent" model
__collection_tpl__ = "users/{id}/stats"
class User(AsyncModel):
__collection__ = "users"
name: str
async def get_user_stats(user_id):
user = await User.get_by_id(user_id)
stats_model: Type[UserStats] = UserStats.model_for(user)
Ideally, the ability to query all user stats (as supported by firestore's group query):
UserStats.collection.find({"reported_at": {"<=": "datetime.datetime.utcnow()"}})
Side note: It would be awesome to not have to retrieve the user before querying its subcollection
UserStats.model_for(user)
or
UserStats.parent(user_id)
Any updates on this?