Join GitHub today
GitHub is home to over 50 million developers working together to host and review code, manage projects, and build software together.
Sign upGitHub is where the world builds software
Millions of developers and companies build, ship, and maintain their software on GitHub — the largest and most advanced development platform in the world.
Implement `.exclude` #62
Conversation
| @@ -94,14 +94,16 @@ def build_select_expression(self): | |||
|
|
|||
| return expr | |||
|
|
|||
| def filter(self, **kwargs): | |||
| def filter(self, exclude=False, **kwargs): | |||
tomchristie
Feb 26, 2020
Member
I wonder if we should use _exclude, to make it private-ish, and help ensure it shouldn't clash with any of the provided kwargs?
I wonder if we should use _exclude, to make it private-ish, and help ensure it shouldn't clash with any of the provided kwargs?
EmilioCarrion
Feb 26, 2020
Author
Totally true, I isolated the parsing logic in a private method avoiding any posible clash with field names
Totally true, I isolated the parsing logic in a private method avoiding any posible clash with field names
| def exclude(self, **kwargs): | ||
| return self._parse_filters(exclude=True, **kwargs) | ||
|
|
||
| def _parse_filters(self, exclude=False, **kwargs): |
rzane
Feb 26, 2020
Contributor
@EmilioCarrion, even with your latest changes, exclude could conflict one of the parameters used for filtering. Take a look at the following example:
class Person(orm.Model):
id = orm.Integer(primary_key=True)
exclude = orm.String(max_length=100)
await Person.filter(exclude=True).all()
The column name exclude conflicts with the exclude parameter in _parse_filters.
One solution would be to change the definition of _parse_filters to the following:
def _parse_filters(self, values, exclude=False):
Alternatively, you could rename exclude to _exclude.
@EmilioCarrion, even with your latest changes, exclude could conflict one of the parameters used for filtering. Take a look at the following example:
class Person(orm.Model):
id = orm.Integer(primary_key=True)
exclude = orm.String(max_length=100)
await Person.filter(exclude=True).all()The column name exclude conflicts with the exclude parameter in _parse_filters.
One solution would be to change the definition of _parse_filters to the following:
def _parse_filters(self, values, exclude=False):Alternatively, you could rename exclude to _exclude.
Co-authored-by: Rafał Pitoń <kontakt@rpiton.com>
| clauses.append(clause) | ||
|
|
||
| if exclude: | ||
| filter_clauses.append(~sqlalchemy.sql.and_(*clauses)) |
rafalp
May 24, 2020
Member
Can we replace unary operator with not_? It will be more obvious that way.
Can we replace unary operator with not_? It will be more obvious that way.
Implemented the .exclude() method in the queryset.
Implemented as a parametrization of the filter method where if we are excluding we invert the sql compose clause