Loopback: Filters that allows for comparison of model properties

Created on 14 Jul 2016  路  6Comments  路  Source: strongloop/loopback

Using loopback where filter would be a lot more versatile if you could do queries that relate the model's instance properties to one another:

{
  where: {
    modelId: id,
    someProp: {
      neq: {
        property: someOtherProp
      }
    }
  }
}

The neq I'm referencing denotes 'not equal' .. eg. someProp != someOtherProp.

Right now, If i want to compare 2 properties I need to go to SQL and do a manual query there. Can this be a feature for future release?

Most helpful comment

Ok @gunjpan I think my point wasn't conveyed very well. Yes I'm aware there is a neq operator already available.

The important part is the property: someOtherProp part - where someOtherProp is actually another property name within the model. It would be similar to doing an SQL query like:

SELECT * FROM myTable WHERE column_A != column_B;

Does that make sense?

-> if using the above as a reference it would be: SELECT * FROM myTable WHERE someProp != someOtherProp;

All 6 comments

@sidewaiise see this sections Operators. There is neq operator for your use case.

@mrbatista thanks for chiming in.
@sidewaiise: Did above suggestion help you? The where filter supports _almost_ all comparison operators.
Closing this now. Should you need further assistance with it, please mention me in the comments and I'll be happy to help. Thank you and have a great weekend :smiley_cat:

Ok @gunjpan I think my point wasn't conveyed very well. Yes I'm aware there is a neq operator already available.

The important part is the property: someOtherProp part - where someOtherProp is actually another property name within the model. It would be similar to doing an SQL query like:

SELECT * FROM myTable WHERE column_A != column_B;

Does that make sense?

-> if using the above as a reference it would be: SELECT * FROM myTable WHERE someProp != someOtherProp;

@gunjpan Any update of this?

it seem so far this issue persists. only mongodb connector has some thing like this with allowExtendedOperators: true setting so your can add $where "this.xxx != this.yyy"

no solution to this problem so far?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Overdrivr picture Overdrivr  路  4Comments

ian-lewis-cs picture ian-lewis-cs  路  4Comments

germanamz picture germanamz  路  3Comments

bajtos picture bajtos  路  4Comments

bryannaegele picture bryannaegele  路  4Comments