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

Is it possible to search attributes of a Resource's assocations? #131

Closed
molenick-mov opened this issue Jan 5, 2022 · 1 comment
Closed

Comments

@molenick-mov
Copy link

I want to search for resource records based on the values of an associated model's attributes.

Say I have a resource/model Order that has many Suborders. When search for Orders, I'd like for it search against both the id attributes of Order and Suborder, and return any orders for that have a matching id for either Order or Suborder. If I perform a search against Orders with a term of '11', I'd expect it to return Orders with an id of 11 as well Orders having a Suborder with an id of 11.

I've been reading through the code and tried to make a derivative HasMany field that's searchable, but get an error with the generated query that orders.sub_orders doesn't exist, which is correct since it's Suborder that holds the foreign key.

Is there any way to configure a resource's search so that it can search against both its attributes and its assocations?

Thanks!

@excid3
Copy link
Owner

excid3 commented Oct 1, 2022

Search is just a simple SQL query builder currently. I'd love to be able to add an easy method for adding joins to allow querying against associated tables.

I'd also love the ability to swap the search out with other implementations like Meilisearch, ElasticSearch.

Currently, you can override scoped_resources in the resource controller to do this. Pagy does work differently for various search engines, so that piece may also need customization.

@excid3 excid3 closed this as completed Apr 28, 2024
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

2 participants