Skip to content
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

Add support for filtering on embedded document fields #186

Closed
madsmtm opened this issue Oct 31, 2018 · 3 comments
Closed

Add support for filtering on embedded document fields #186

madsmtm opened this issue Oct 31, 2018 · 3 comments

Comments

@madsmtm
Copy link

madsmtm commented Oct 31, 2018

See eve/features#filtering, their example does not work with Eve-SQLAlchemy:

http://eve-demo.herokuapp.com/people?where={"location.city": "San Francisco"}

We could fix this by changing parser.py#L63 (and maybe parser.py#L221) to something that recursively finds the attribute, e.g.:

k_split = iter(k.split('.'))
attr = getattr(model, next(k_split))
for x in k_split:
    attr = getattr(attr.property.argument, x)

Though I'm not sure if this would encompass all cases, or have unexpected side effects

@madsmtm
Copy link
Author

madsmtm commented Nov 1, 2018

I can make a PR, and see if it passes the existing test suite, but I'd like an opinion on the approach first, it feels hacky ;)

@dkellner
Copy link
Collaborator

dkellner commented Nov 5, 2018

Thanks for reporting this!

We should introduce a failing test before we change the implementation. Is there a test in Eve itself that covers this already? A quick look in tests/get.py does not show any skipped tests regarding to this kind of lookups.

Regarding the implementation: parse_sorting (https://github.com/pyeve/eve-sqlalchemy/blob/master/eve_sqlalchemy/parser.py#L143) seems to have some handling of child attributes already, but at first glance it looks like it cannot handle more than one level. It would be good to use the same code for translating the lookup strings to attributes in both cases, e.g. move this lookup in a separate function.

@Alan01252
Copy link

Alan01252 commented Nov 27, 2018

I wonder if it's worth documenting the fact that you can use AssociationProxies instead to achieve similar functionality? In the above

location_relation = relationship("Location", secondary="location")
city = association_proxy('location_relation', 'city')

The query above is:

http://eve-demo.herokuapp.com/people?where={"city": "San Francisco"}

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

No branches or pull requests

3 participants