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

Does this work with nested fields and related models? #19

Open
dschreij opened this issue Feb 26, 2021 · 1 comment
Open

Does this work with nested fields and related models? #19

dschreij opened this issue Feb 26, 2021 · 1 comment

Comments

@dschreij
Copy link

Hi there. I have a model which includes relationships. I include relationship data with the .with() function.
Even though fuse says it supports search of nested fields using the dot notation (https://fusejs.io/examples.html#nested-search), the neste fields of my model do not seem to be picked up.

const inquiries = computed(() => {
  const query = Inquiry.query()
    .has('shipment')
    .with('shipment.origin|destination')
    .with('user')
    .orderBy('created_at', 'desc')
  if (searchterm.value?.length > 2) {
    query.search(searchterm.value, {
      keys: ['status', 'shipment.hubspot_deal_id', 'user.first_name', 'user.last_name']
    })
  }
  return query.get()
})

If I search the status field. It appears to be working correctly. But if I try to search a user by first name or last name, the search result turns up empty.

So I guess my questions are:

  • Does this plugin support the situation above, in which one wants to search nested fields, that consist of related models included using with()?
  • When is the search executed? Is this before the .with() functions have successfully executed, or after?
@bpuig
Copy link

bpuig commented May 23, 2021

For me dot notation does not work either, but you can:

.has('shipment', (query) => {
  if (searchterm.value?.length > 2) {
    query.search(searchterm.value, {
      keys: ['hubspot_deal_id']
    })
  }
})

Form me it's even better than dot because I can find more easily where I'm searching

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