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

How to filter fastjoin datas #360

Closed
amuchembled opened this issue Feb 14, 2018 · 6 comments
Closed

How to filter fastjoin datas #360

amuchembled opened this issue Feb 14, 2018 · 6 comments

Comments

@amuchembled
Copy link

Hello,

I've make two test services :

  • Countries :
    • Label
  • Cities
    • Label
    • countries_id

In order to get the country label, when calling the cities endpoint, i've used fastjoin which works very well.

But my question is : How do I filter my request by passing a label value instead of an object ID ?

Example :
FROM : GET /cities?countries_id=1234...
TO : GET /cities?countries.label="Paris" (or something like that)

Thanks for your help !

@eddyystop
Copy link
Collaborator

eddyystop commented Feb 14, 2018

You do not mention if you want to use BatchLoaders or not. I'll assume not. Both records have a label field. I'll assume you want to join a Countries record to a Cities record using them.

module.exports = {
  joins: {
    colours: (...args) => async (city, context) => {
        city.country = await context.app.service('countries').find({
            query: { label: city.label }, paginate: false
        })
    }  } };

@amuchembled
Copy link
Author

Thanks for your answer, but this is not really what I wanted, I think.

Let me give you a more precise example :

A countries document :
{
id: "1234",
label : "France"
}

A cities document :
{
id: "5678",
label : "Paris",
countries_id: "1234"
}

When I make a get rest query to "/cities", i want to get the label of the country, populated thanks to fastjoin. Which works great by joining with the ids, in an "after all" hook.

I get something like that as a result :
{
id: "5678",
label : "Paris",
country: {
id: "1234",
label : "France"
}
}

But my real problem now, is to be able to filter this result by selecting a specific country label (from Postman for example).

Ex : GET /cities?countries[label="France"]

Is it possible ?

I've remarqued that populated fields are not known, to the query selector, I can only filter by "countries_id", which is not very sexy to use.

I dont use batchloaders at the moment

@eddyystop
Copy link
Collaborator

How would you code that using normal Feathers services, without fastJoin?

@amuchembled
Copy link
Author

I have no idea :/

@eddyystop
Copy link
Collaborator

eddyystop commented Feb 16, 2018 via email

@eddyystop
Copy link
Collaborator

I think you can get the results you want with GET /countries[label="France"]?cities

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