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

Filtering on association field #203

Open
fstn opened this issue Jan 2, 2017 · 2 comments
Open

Filtering on association field #203

fstn opened this issue Jan 2, 2017 · 2 comments

Comments

@fstn
Copy link

fstn commented Jan 2, 2017

Hi, Is there any way to filter on association column?

Sequelize equivalent:

Project.findAll({
include: [{
model: Task,
where: {"name":"myTask"}
}]
})

this is what I want to query:

http://localhost/project?task.name=myTask

@douglas-hirsh
Copy link

I am interested in doing this too. I am wondering if there would be a place that we could inject the logic to handle this?

Thanks,
Douglas

@AkselsLedins
Copy link

Something like that

  Project.use({
    list: {
      fetch: {
        before(request, response, context) {
          if (!isEmpty(request.query) && request.query.name) {
              context.include = [{
                model: Task,
                attributes: [ 'name' ],
                where: { name: request.query.name },
              }];
          }
          return context.continue;
        },
      },
    },
  });

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

3 participants