mswjs / data

Data modeling and relation library for testing JavaScript applications.

Home Page:https://npm.im/@mswjs/data

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Query (findMany, findFirst) ignores Array type fields.

zorgick opened this issue · comments

It seems like models, that have a field with an Array type, cannot be queried.

A simple model, where roles field is an array of numbers:

const db = factory({
  user: {
    id: primaryKey(() => faker.datatype.uuid()),
    name: () => faker.name.fullName(),
    age: () => faker.datatype.number(),
    roles: () => faker.helpers.arrayElements([1, 2, 3, 4])
  }
});

is ignored by findMany query:

const usersRoleSubset = db.user.findMany({
  where: {
    roles: {
      // no matter, which query (notIn, between) to use arrays are ignored
      in: [2, 3]
    }
  }
});

A reproducable example can be found here: https://codesandbox.io/s/flamboyant-shadow-rmb5gk?file=/src/index.js