Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter by item contained in a list in realm react native?

I'm doing the following query:

realm.objects('Maker').filtered("categories CONTAINS $0", categoryObject)

But I'm getting this error:

Only 'equal' and 'not equal' operators are supported for object comparison

And here's my schema:

{ 
name: 'MakerOption',
primaryKey: 'serverId',
properties: {
  serverId: 'int',
  name: 'string',
  categories: {type: 'list', objectType: 'Category'},
}

{
name: 'Category',
primaryKey: 'serverId',
properties: {
  serverId: 'int',
  name: 'string'
}

The documentation is quite sparse on this subject. Is there an alternative method for doing this?

like image 796
Paulo Cesar Avatar asked Feb 04 '23 07:02

Paulo Cesar


1 Answers

Filtering by properties on linked or child objects can be done by specifying a keypath in the query e.g. car.color == 'blue'

So you are looking for the following query:

realm.objects('Maker').filtered("categories.serverId == $0", categoryObject.serverId)
like image 59
EpicPandaForce Avatar answered Feb 11 '23 01:02

EpicPandaForce