Skip to content

Arrays in filters are not parsed correctly #120

Description

@tlconnor

According to the documentation:

Arrays are supported automatically, defaulting to an OR clause:

Person.where({ name: ["Joe", "Bill"] }).all()

GET /people?&filter[name][]=Joe&filter[name][]=Bill

This does not appear to be the case - the implementation of parameterize() will concatenate array values rather than splitting them. This means that instead of the documented behavior above, you get:

Person.where({ name: ["Joe", "Bill"] }).all()

GET /people?&filter[name]=Joe,Bill

Here is an example test that illustrates the problem:

it("casts arrays correctly", () => {
  scope = scope.where({ name: ["Joe", "Bill"] })
  expect((<string>scope.toQueryParams())).to.eq("filter[name][]=Joe&filter[name][]=Bill")
})

The result of this test is:

AssertionError: expected 'filter[name]=Joe,Bill' to equal 'filter[name][]=Joe&filter[name][]=Bill'

  • expected - actual

-filter[name]=Joe,Bill
+filter[name][]=Joe&filter[name][]=Bill

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions