agateblue / lifter

A generic query engine, inspired by Django ORM
ISC License
449 stars 16 forks source link

Allow querying on field that do not exist on all models #26

Closed agateblue closed 8 years ago

agateblue commented 8 years ago

Currently, if you query on a field that do not exist on all models, lifter will raise an error. Making this behaviour optional, would be an improvement. Example:

manager.filter(User.optional_field.exists(), User.optional_field == 'value')

This was first raised on reddit

Permafacture commented 8 years ago

+1

It would be good to have the opposite filter also, ie: User.optional_field.does_no_exist().

I wonder if optional_field is not None (since people are used to dict.get returning None if the lookup fails) or optional_field is Exists would make sense.

agateblue commented 8 years ago

I don't like the idea of created two methods, instead, you can use the ~ operator, that inverts a query (this work with any query ;).

Filter objects with the field:

manager.filter(Model.optional_field.exists())

Filter objects without the field:

manager.filter(~Model.optional_field.exists())