How can I filter same field on 2 different values in a relationMapping of Objection.js

Viewed 220

I have a relation mapping in a Objection.js model and I need to set a filter on a field, but this field must be filtered by 2 possible values null or 0.

This is an example of relation like one i use:

static get relationMappings() {
  return {
    dipendenti: {
      relation: Model.ManyToManyRelation,
      modelClass: path.join(__dirname, '/DestModel'),
      filter: {
        [`field1`]: [null],
      },
      join: {
        from: `fromField`,
        through: {
          modelClass: path.join(__dirname, '/ThroughModel'),
          from: `throughFromField`,
          to: `throughToField`
        },
        to: `toField`
      }
    }
  };
}

I tried these two methods, but neither works:

filter: {
  [`field1`]: [null, 0],
},

filter: {
  [`field1`]: [null],
  [`field1`]: [0],
},

Somebody know the right way for filter a field by 2 values using Objection.js?

1 Answers

At the end I used .modifyEager() but this is not the way I that I was looking for

Related