2
votes

Working with LB4 framework and Postgres for DB, using "loopback-connector-postgresql": "^3.7.0" for DB connectivity and facing issue while using find query with where operator to fetch list of data by matching value in an array and the query used is shared below,

sample table data:

[{id: 1,
roll: [1,4]
},{  
id:2,
roll: [1,3],
},{
id:3,
roll: [2,4]
}]

In model roll marked mandatory

Query used: this.repository.find({where: { roll: { inq: [4] }}});

Expected output:

[{id: 1,
roll: [1,4]
},{
id:3,
roll: [2,4]
}]

for the above code snippet typescript in loopback4 throws the below error

*Argument of type '{ where: { roll: { inq: number[]; }; }; }' is not assignable to parameter of type 'Filter<ModelRow>'.
  Types of property 'where' are incompatible.
    Type '{ row: { inq: number[]; }; }' is not assignable to type 'Condition<ModelRow> | AndClause<ModelRow> | OrClause<ModelRow> | undefined'.
      Type '{ row: { inq: number[]; }; }' is not assignable to type 'Condition<ModelRow>'.
        Types of property 'row' are incompatible.
          Type '{ inq: number[]; }' is not assignable to type 'PredicateComparison<number[]> | (number[] & string) | (number[] & number) | (number[] & false) | (number[] & true) | (number[] & Date) | undefined'.
            Type '{ inq: number[]; }' is not assignable to type 'undefined'.ts(2345)*
1
I'm facing a similar issue at the moment. Did you find a fix? - Rizz
@Rizz no fix found and eagerly waiting for the loopback communities response which seems to be questionable - sunilsmith
@sunilsmith Most of the community is in the community Slack (which the link you can find on the LoopBack website) and GitHub. - Rifa Achrinza

1 Answers

0
votes

I got the same issue, but with string. Hacked it with cast to any and custom wrapper. May be it's possible to hack numbers in this way too. Dirty solution

where: {rolls: {inq: [`"{${rollValue}}"`] as any}},