lumber icon indicating copy to clipboard operation
lumber copied to clipboard

Search is not working when using attributes from other tables

Open facundofarias opened this issue 5 years ago • 7 comments

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

facundofarias avatar Jul 03 '18 16:07 facundofarias

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?

arnaudbesnier avatar Aug 21 '18 07:08 arnaudbesnier

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!

facundofarias avatar Aug 21 '18 07:08 facundofarias

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?

arnaudbesnier avatar Aug 22 '18 07:08 arnaudbesnier

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

facundofarias avatar Aug 22 '18 07:08 facundofarias

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

rgull avatar Mar 20 '19 15:03 rgull

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

facundofarias avatar Mar 21 '19 20:03 facundofarias

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?

arnaudbesnier avatar Feb 03 '20 14:02 arnaudbesnier