feathers-pinia icon indicating copy to clipboard operation
feathers-pinia copied to clipboard

v4.1.1 - useFind - No Results if query param result is populated

Open palmtown opened this issue 1 year ago • 1 comments

Hello Community,

I've found an issue with using useFind. In short, when executing the code in Exhibit 1, feathers-pinia successfully queries my backend server which returns the results. However, the messages$.total variable shows the correct total, however, $messages.data is empty.

After debugging, I've found the issue and it is with the findInStore method that executes as part of the useFind function. In short, when I query using user=userId as shown in Exhibit 1, and on the backend I populate the user variable with the user's object, findInStore fails to find the data in the local store as user=userId doesn't match the returned data. In the returned data the user is now popluated with an object rather than a string (e.g. user={_id: "someid"...} opposed to user=userId).

Also, I tried altering the query with {query: {user: {_id: "some_id"}}, however, that doesn't work and findInStore is unable to match results using this query.

Any suggestions?

Exhibit 1 ` const { api } = useFeathers()

const params = computed(() => { return { query: { user: props.userId } } }) const messages$ = api.service('messages').useFind(params, { paginateOn: 'hybrid' }) `

Note that this issue is similar to https://github.com/marshallswain/feathers-pinia/issues/142 however, in that issue, no parameters are passed in the query. Whereas in this issue, the problem is passing parameters to the query that changes on the backend due to populating the variable.

palmtown avatar Dec 10 '23 07:12 palmtown

I should document that useFind is only intended to work if your frontend and backend data structures match. There's no way to automatically configure two separate, custom data structures. In this case, you'll need to use service.find and service.findInStore manually.

marshallswain avatar Jan 22 '24 04:01 marshallswain