Skip to content

How does one find a model with a None field value? #485

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
YaraslauZhylko opened this issue Feb 17, 2023 · 1 comment
Open

How does one find a model with a None field value? #485

YaraslauZhylko opened this issue Feb 17, 2023 · 1 comment

Comments

@YaraslauZhylko
Copy link
Contributor

I have a model like this:

class City(JsonModel):
    country_id: str = Field(index=True)
    region_id: str | None = Field(index=True)

How do I query for a city in a specific country that is not associated with any region? I.e.: a capital or a large city like Bremen in Germany?

The following queries do not work and raise errors:

cities = City.find((City.country_id == "de") & (City.region_id is None)).all()

aioredis_om.model.model.QuerySyntaxError: Counld not resolve field name. See docs: TODO
cities = City.find((City.country_id == "de") & (City.region_id == None)).all()

TypeError: argument of type 'NoneType' is not iterable

I failed to find any reference in the docs about scenarios like that... 🤔

P.S.: SQLAlchemy has .filter(City.region_id == None) or .filter(City.region_id.is_not(None)) to handle those cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant