nestjs-query icon indicating copy to clipboard operation
nestjs-query copied to clipboard

[Question / Feature Request] Support for filterable array fields

Open amille14 opened this issue 4 years ago • 7 comments

Is there any way to have a filterable array field? For example, I have a type/entity with an array of tags like so:

@Field(type => [String])
@Column('jsonb', { default: [] })
tags: string[]

If I change the @Field decorator to a @FilterableField decorator, it breaks with a TypeError: Cannot read property 'charAt' of undefined error. I assume this is because filterable array fields are not supported? I didn't find anything about it in the docs.

I would like to be able to query for records that contain a specific tag(s) within the tags array or that have a certain length of the tags array.

amille14 avatar Apr 20 '20 15:04 amille14

I'll have to look into how this could be supported, or how generic it could be I think this would depend on the dialect that is being used.

In postgres we could use jsonb but I'm unsure about others. If you have any suggestions I'd love to hear them.

Thanks!

doug-martin avatar Apr 22 '20 20:04 doug-martin

I stumbled upon this one as well. In my case I am using it for phone numbers on contact. I am using Postgres as DB with a column type of text[]

Currently the attribute looks as follows:

  @Column({ array: true, type: 'text' })
  @Field(() => [String], { nullable: true })
  phoneNumbers: string[];

wowczarczyk avatar Oct 05 '20 11:10 wowczarczyk

Hi! Any progress on this topic? I am creating an API in the same line as the @amille14 example where the search by tags is very important since it is an API for a store. In my case I use MongoDB as a database with mongoose. In case of not being able to use @FilterableField, is there any other standardized alternative that allows searching by array field?

carmona44 avatar Jun 21 '21 07:06 carmona44

I am needing this as well. for mongoose/typegoose it is straightforward but I am not sure if it is easy(or feasible) for other SQL databases. Can someone setup a general plan for SQL part? I can help with the NoSQL/MongoDB part.

onichandame avatar Jul 29 '21 03:07 onichandame

I guess its safe to say that not all dbs that TypeORM or sequelize support are able to work with array columns. When using TypeORM, you can use the simple-array column type to mitigate that, but I don't know how things are with sequelize. Does anyone have an idea there?

psteinroe avatar Aug 05 '21 12:08 psteinroe

Face the same issue on my project. Are there any updates here?

ginvaell avatar Nov 17 '21 15:11 ginvaell

Is this still an issue? Seems very strange that this is not supported since NestJs supports array fields

FBurner avatar Apr 02 '22 21:04 FBurner