firedantic icon indicating copy to clipboard operation
firedantic copied to clipboard

Support collection group queries

Open gresnick opened this issue 3 years ago • 1 comments

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)

gresnick avatar Feb 16 '22 07:02 gresnick

Any updates on this?

RouvenG avatar Sep 23 '24 14:09 RouvenG