Skip to content
This repository has been archived by the owner on Jun 14, 2024. It is now read-only.

Search is not working when using attributes from other tables #148

Open
facundofarias opened this issue Jul 3, 2018 · 7 comments
Open

Comments

@facundofarias
Copy link

Hallo there,

I've read these docs hundred of times, trying to make it work, but still I am encountering issues. Following the documentation, it's quite straightforward to search in a Smart Field, that's OK.

But in our case, let's suppose we have a table of Pets, with all the information about each pet. If we want to search for a given pet, it's fine, we just use ForestAdmin UI, and it's all good. The problem is, if we want to search for example, using the Pet Owner's name, which is stored in a different table, and in the Pets table we have its ID only.

I think it's a common scenario to cover, since for example all our CS agents want to search on all the tables by Email (the easiest way to identify a given customer), and like Stripe does, show all the results related to that email.

I've been trying to find samples implementing this scenario, since I know big companies like Hitch are using it, but I couldn't find none. Can you provide an example? I can also share with you what I have done, but is not working :/

Thanks,
Facundo

@arnaudbesnier
Copy link
Member

Hi @facundofarias , could you provide some examples of what you tried to implement the search on your Smart Fields?

In an operational point of view, about your example, why don't you search directly in the Owner table?

@facundofarias
Copy link
Author

Hey @arnaudbesnier,
Let me explain a bit more about our scenario.

We do have a Users table in which, of course, the search can be done using the Email field, and also we have created the Smart Relationships, so once I found the user that I am interested, I can navigate to the other relationships.

But in this case, let's suppose we have another table called Invoices, in which we have a field called UserId -> In this case, the users want to search by Email, not by UserId. So, if we search by UserId, yes, we got the results. Now, if we try to search using the Email field, no results are shown. So, basically, how can we achieve that? We kindof done it by creating views, that contains all the fields (including the Email), and thus, the search is working. But it's a workaround, we don't think it's the proper solution.

More or less do you understand our use case?
Thanks!

@arnaudbesnier
Copy link
Member

Hi @facundofarias ,

About your Invoices example if the userId is a "native" belongsTo (ie not a Smart BelongsTo) then if you want to search on Users.email from the Invoices you can activate the "extended search". You can do that from the footer of the Invoices table view.

screen shot 2018-08-22 at 09 01 11

Now if you are in the case of a Smart BelongsTo, then the search implementation of the Smart BelongsTo is more complex than the simple example provided in the documentation. You need to be able to manipulate the query Sequelize object to add your conditions and tell the ORM that you need to set those conditions on a join table.

As you're not the only person to ask for such example, we'll work on this.
Is it ok for you, if we provide an example of this next week?

@facundofarias
Copy link
Author

@arnaudbesnier exactly, that's our problem!
An example would be great! Thanks

@rgull
Copy link

rgull commented Mar 20, 2019

Hi, Any updates on this. We also need an example for Search on a Smart Relationship. Thanks.

@facundofarias
Copy link
Author

No idea! @arnaudbesnier Was the article published? Where is it?
Thanks

@arnaudbesnier
Copy link
Member

Hi @facundofarias
Really sorry for late reply.

Reading the full conversation, it looks like your have a "native" configuration:

  • invoices belongsTo users
  • users hasMany invoices

If so you can activate the extended search for the Forest Admin panel and everything should work as you expect to.

Is that you case?

Maybe you could share you invoices and users models and associations?

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

No branches or pull requests

4 participants