1

I want to get the result with include relation with where condition on include model.

return this.htcApi.find({
  include: [
    {
      relation: 'nmos',
      scope: {
        include: 'countries',
      },
    },
  ],
  where: { name:'Welcome', "nmos.name":'agile'}
});

This where is condition work for name of htc model not for noms module.

I want query like

Select htc.*, nmos.* FROM htc LEFT JOIN nmos ON nmos.id = htc.n_id where htc.name = 'abc' and nmos.name = 'abc';

How can add where condition on the "relation" table?

2 Answers 2

1

Simply you need to add where clause in 'scope' object which lies inside the 'include' object. So the code would be like :

    return this.htcApi.find({
    include: [
      {
        relation: 'nmos',
        scope: {
          include: 'countries',
          where:{name:'agile'}
        },
      },
    ],
    where: { name:'Welcome'}
  });
Sign up to request clarification or add additional context in comments.

Comments

0

In your query, you just need to add the property where within the scope property, like this:

return this.htcApi.find({
  include: [
    {
      relation: 'nmos',
      scope: {
        include: 'countries',
        where: {
          and [
            { id: htc.n_id },
            { name: 'abc' },
          ],
        },
      },
    },
  ],
  where: { name: 'abc' }
});

This should return the htcApi objects named 'abc' with the related nmos objects that have the name 'abc' and the id 'n_id'.

1 Comment

I assumed you already had it before making the request! Indeed it's not defined in the code provided

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.