Skip to content

Postgresql column as text[] or character varying() is returning data as string #467

Closed
@prernagp

Description

@prernagp

I have created a model that has an array field of categories. Here is the property definition:-

@property({
    type: 'string',
    postgresql: { columnName: 'categories', dataType: 'ARRAY', dataLength: null, dataPrecision: null, dataScale: null, nullable: 'YES' },
  })
  categories?: string;

And when I apply filters like this:

 const filter1: any = {
      where: {
        categories: { contains: ['ViewLibrarySong'] },
      },
    };
    return this.blogRepository.find(filter1);

I am getting value of the column as string here. i.e. operatorValue's value is '["ViewLibrarySong"]'.

case 'contains':
      return new ParameterizedSQL(columnName + ' @> array[' + operatorValue.map((v) => `'${v}'`) + ']::'
        + propertyDefinition.postgresql.dataType);

The application is getting crashed as map will not work on string.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions