-
Notifications
You must be signed in to change notification settings - Fork 51
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
Adding relationships attributes filtering #83
Comments
It would be an interesting addition as an optional filter. The filtering right now is inspired by the Mongo model ( Mongo's subdocument querying doesn't translate well to Potion. Instead you should make a custom filter, call it |
Not really sure how to implement the second option, the AttrsFilter given that I would recursively apply the standard filters on the related model fields. |
Something along the lines of:
I will be too busy at least the next month to implement any more of this myself. However, if you can submit a PR with some tests I will be happy to review and merge it. |
Thanks for the hint, I'll see what I can get |
The now defunct flask-peewee project had something like this as well: Peewee and MongoEngine support for such a filter would be nice as well. Or at the very lease, a clear path to adding support (an extensible implementation). |
@lyschoening so I'm trying to follow your hint but here https://github.com/shipperizer/potion/blob/relationship_attr_querying/flask_potion/filters.py#L243 {'properties': {'$attr': {'properties': {'name': {'anyOf': [<werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>]}, 'alpha_id': {'anyOf': [<werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>, <werkzeug.utils.cached_property object at 0x7f4c295a82e8>]}}, 'type': 'object'}}, 'additionalProperties': False, 'required': ['$attr'], 'type': 'object'} that fails the json schema validation. |
@shipperizer I forgot the step where the filter class is initialized in my quick example earlier. The code should be written so that it generates filters for all fields on the target resource except those that would result in loops. This is a similar implementation as on the manager: https://github.com/shipperizer/potion/blob/relationship_attr_querying/flask_potion/manager.py#L50 Coming to think of it, instead of initializing new filters from scratch, you could just access the target field manager's |
Looks like I got it working for the base case (1 relationship, one field), https://github.com/shipperizer/potion/commits/relationship_attr_querying |
Having some issues after starting to test, looks like the field.target is a cached property as well, so for some reason when the field.ToMany or toOne have the resource that is not an object but the string name get an error as the API is not bound to it. I tried to enforce it with the target_reference.resolve method but i still have issues as the resource gets initialised later in the code. Any idea on how to fix it? |
Would it be useful to anyone having a filtering on relationships' attributes?
I have a chunk of code (not really well tested but seems to be working) that allow me to query on a relationship attribute django-style ('A.relationship__attribute')
just overriding the SQLAlchemyManager can work:
it would be good to know if there are better ways to do that and if it could be useful to someone else as well
The text was updated successfully, but these errors were encountered: