# Filtering/sorting on an enum array

**URL:** <https://community.forestadmin.com/t/filtering-sorting-on-an-enum-array/7236>\
**Category:** Help me!\
**Created:** [June 4, 2024, 5:28pm UTC](https://community.forestadmin.com/t/filtering-sorting-on-an-enum-array/7236 "2024-06-04T17:28:41Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [June 4, 2024, 5:28pm UTC](https://community.forestadmin.com/t/filtering-sorting-on-an-enum-array/7236/1 "2024-06-04T17:28:41Z")

</div>

Hello, I have a table “category” with a field “locales” that is an enum array (`category_locales_enum[]`).

## Feature(s) impacted

- Filtering on an enum array
- Sorting on an enum array

## Observed behavior

Filtering or sorting in FA dashboard on this array throws an error. FA casts the array enum as `enum_public.category_locales[]` instead of `category_locales_enum[]`). The `enum_public.category_locales[]` doesn’t appear in our **.forestadmin-schema.json** so I assume it’s being generated somewhere at runtime. If the fix would take long, would you mind pointing me to where it is being generated so that I can patch a workaround in the meantime, thanks.

## Expected behavior

Filtering or sorting in FA dashboard works.

## Failure Logs

The stacktrace is sadly not very helpful here.

```javascript
[forest] 🌳🌳🌳 Unexpected error: type "enum_public.category_locales[]" does not exist
{
  "name": "SequelizeDatabaseError",
  "parent": {
    "length": 118,
    "name": "error",
    "severity": "ERROR",
    "code": "42704",
    "position": "115",
    "file": "parse_type.c",
    "line": "270",
    "routine": "typenameType",
    "sql": "SELECT count(*) AS \"count\" FROM \"public\".\"category\" AS \"category\" WHERE \"category\".\"locales\" @> ARRAY['en']::\"enum_public.category_locales\"[];"
  },
  "original": {
    "length": 118,
    "name": "error",
    "severity": "ERROR",
    "code": "42704",
    "position": "115",
    "file": "parse_type.c",
    "line": "270",
    "routine": "typenameType",
    "sql": "SELECT count(*) AS \"count\" FROM \"public\".\"category\" AS \"category\" WHERE \"category\".\"locales\" @> ARRAY['en']::\"enum_public.category_locales\"[];"
  },
  "sql": "SELECT count(*) AS \"count\" FROM \"public\".\"category\" AS \"category\" WHERE \"category\".\"locales\" @> ARRAY['en']::\"enum_public.category_locales\"[];",
  "error@context": {
    "_ns_name": "forest-admin",
    "id": 7941
  },
  "stack": "SequelizeDatabaseError: type \"enum_public.category_locales[]\" does not exist\n at Query.formatError (/path-to-project/forest-admin/node_modules/sequelize/lib/dialects/postgres/query.js:366:16)\n at /path-to-project/forest-admin/node_modules/sequelize/lib/dialects/postgres/query.js:72:18\n at clsBind (/path-to-project/forest-admin/node_modules/cls-hooked/context.js:172:17)\n at tryCatcher (/path-to-project/forest-admin/node_modules/bluebird/js/release/util.js:16:23)\n at Promise._settlePromiseFromHandler (/path-to-project/forest-admin/node_modules/bluebird/js/release/promise.js:547:31)\n at Promise._settlePromise (/path-to-project/forest-admin/node_modules/bluebird/js/release/promise.js:604:18)\n at Promise._settlePromise0 (/path-to-project/forest-admin/node_modules/bluebird/js/release/promise.js:649:10)\n at Promise._settlePromises (/path-to-project/forest-admin/node_modules/bluebird/js/release/promise.js:725:18)\n at _drainQueueStep (/path-to-project/forest-admin/node_modules/bluebird/js/release/async.js:93:12)\n at _drainQueue (/path-to-project/forest-admin/node_modules/bluebird/js/release/async.js:86:9)\n at Async._drainQueues (/path-to-project/forest-admin/node_modules/bluebird/js/release/async.js:102:5)\n at Immediate.Async.drainQueues [as _onImmediate] (/path-to-project/forest-admin/node_modules/bluebird/js/release/async.js:15:14)\n at processImmediate (node:internal/timers:478:21)\n at process.callbackTrampoline (node:internal/async_hooks:130:17)"
}

```

## Context

- Project name: contact me by email if necessary
- Team name: contact me by email if necessary
- Environment name: development
- Agent & database:

```json
{
    "liana": "forest-express-sequelize",
    "liana_version": "9.3.7",
    "stack": {
      "database_type": "postgres",
      "engine": "nodejs",
      "engine_version": "20.9.0",
      "orm_version": "5.22.5"
    }
  }

```

---

<div class="post-metadata">

**Author:** ![nbouliol](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/nbouliol/32/5777_2.png) [@nbouliol](https://community.forestadmin.com/u/nbouliol)\
**Post date:** [June 5, 2024, 9:02am UTC](https://community.forestadmin.com/t/filtering-sorting-on-an-enum-array/7236/2 "2024-06-05T09:02:28Z")

</div>

Hello @louisl

I can reproduce you issue, but looking at the agent code and the sequelize documentation

I think the issue is more related to the the way sequelize handles queries on enum arrays

See the [sequelize documentation](https://sequelize.org/docs/v6/other-topics/dialect-specific-things/#data-type-arrayenum---postgresql-only) on enum arrays (it’s the same for sequelize v5 and v6)

Best regards,  
Nicolas

---

<div class="post-metadata">

**Author:** ![louisl](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/louisl/32/5257_2.png) [@louisl](https://community.forestadmin.com/u/louisl)\
**Post date:** [June 7, 2024, 10:34am UTC](https://community.forestadmin.com/t/filtering-sorting-on-an-enum-array/7236/3 "2024-06-07T10:34:51Z")

</div>

Thanks, that’s unexpected from an ORM… We’ll look how we handle this
