Skip to content

Setting arrayFields to true does not work #32

@jmikrut

Description

@jmikrut

Hi there, this package is amazing. We're looking to implement it within Payload and we're currently stuck on an issue.

We have a JSON column that stores a JSON array at the root, like this:

[
  {
    "children": [
      {
        "text": "hello"
      }
    ]
  },
  {
    "children": [
      {
        "text": "i am some"
      },
      {
        "bold": true,
        "text": "SlateJS rich text"
      }
    ]
  }
]

As you can see, the root of the JSON stored in our jsonb column is an array. We were hoping to use the true value for arrayFields, so that all paths would be checked as arrays accordingly (or at the very least, the root and any children property).

But it appears that the true argument never makes its way into the convert method, as it is currently stripped out immediately when this package is invoked, within this code:

module.exports = function (fieldName, query, arraysOrOptions) {
  let arrays
  let options = {}
  if (arraysOrOptions && Array.isArray(arraysOrOptions)) {
    arrays = arraysOrOptions
  } else if (typeof arraysOrOptions === 'object') {
    arrays = arraysOrOptions.arrays || []
    options = arraysOrOptions
  }
  return convert([fieldName], query, arrays || [], false, options)
}

So I've discovered a potential problem there. But I've also got an overarching question in general - how would we query the column as if the column root itself were an array? I tried all sorts of things but I don't think the package is currently set up to work this way.

Thank you!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions