mswjs / data

Data modeling and relation library for testing JavaScript applications.
https://npm.im/@mswjs/data
MIT License
822 stars 52 forks source link

Query (findMany, findFirst) ignores Array type fields. #249

Open zorgick opened 2 years ago

zorgick commented 2 years ago

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