crud icon indicating copy to clipboard operation
crud copied to clipboard

Filtering does not work on embedded fields

Open Marko298 opened this issue 3 years ago • 7 comments

If I try to filter query by field in embedding I receive 500 error. Request /farms?filter=customerStatus.feedAccountNumber||$eq||8999996

Error [Nest] 52408 - 03/15/2021, 12:44:12 PM [ExceptionsHandler] ER_BAD_FIELD_ERROR: Unknown column 'customerStatus.feedAccountNumber' in 'where clause' +114696ms QueryFailedError: ER_BAD_FIELD_ERROR: Unknown column 'customerStatus.feedAccountNumber' in 'where clause'

Farm Class

@Entity('farms')
export class Farm {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column(() => CustomerInfo)
  customerStatus: CustomerInfo;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;
}

CustomerInfo class

export class CustomerInfo {
  @Column({
    type: 'enum',
    enum: FeedCustomerStatus,
    default: FeedCustomerStatus.INACTIVE,
  })
  feedStatus?: FeedCustomerStatus;

  @Column({ nullable: true })
  feedAccountNumber?: string;

  @Column({
    type: 'enum',
    enum: PulletCustomerStatus,
    default: PulletCustomerStatus.INACTIVE,
  })
  pulletStatus: PulletCustomerStatus;

  @Column({ nullable: true })
  pulletAccountNumber?: string;

  @Column({ nullable: true })
  accountName?: string;
}

I tried join, alias, nothing helped

Marko298 avatar Mar 15 '21 10:03 Marko298

How does look your @Crud({...}) At the farmController?

Manokero avatar Apr 17 '21 18:04 Manokero


@Crud({
  model: {
    type: Farm,
  },

  dto: {
    create: FarmDto,
    update: PartialType(FarmDto),
  },

  query: {
    limit:          25,
    maxLimit:       100,
    alwaysPaginate: true,
    join:           {
      tags:                { eager: true, allow: ['id', 'name', 'color'] },
      teams:               { eager: true, allow: ['id', 'name'] },
      customerStatus:      { eager: true },
    },

    sort: [{ field: 'name', order: 'ASC' }],
  },
})

Marko298 avatar Apr 20 '21 06:04 Marko298

If I try to filter query by field in embedding I receive 500 error. Request /farms?filter=customerStatus.feedAccountNumber||$eq||8999996

Error [Nest] 52408 - 03/15/2021, 12:44:12 PM [ExceptionsHandler] ER_BAD_FIELD_ERROR: Unknown column 'customerStatus.feedAccountNumber' in 'where clause' +114696ms QueryFailedError: ER_BAD_FIELD_ERROR: Unknown column 'customerStatus.feedAccountNumber' in 'where clause'

Farm Class

@Entity('farms')
export class Farm {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  name: string;

  @Column(() => CustomerInfo)
  customerStatus: CustomerInfo;

  @CreateDateColumn()
  createdAt: Date;

  @UpdateDateColumn()
  updatedAt: Date;
}

CustomerInfo class

export class CustomerInfo {
  @Column({
    type: 'enum',
    enum: FeedCustomerStatus,
    default: FeedCustomerStatus.INACTIVE,
  })
  feedStatus?: FeedCustomerStatus;

  @Column({ nullable: true })
  feedAccountNumber?: string;

  @Column({
    type: 'enum',
    enum: PulletCustomerStatus,
    default: PulletCustomerStatus.INACTIVE,
  })
  pulletStatus: PulletCustomerStatus;

  @Column({ nullable: true })
  pulletAccountNumber?: string;

  @Column({ nullable: true })
  accountName?: string;
}

I tried join, alias, nothing helped

Excuse me, has this problem been resolved later? How to solve it?

chf007 avatar Aug 17 '21 10:08 chf007

I just created fields that mirrored content of embedded ones. I don't know whether this was fixed or not

I just created fields that mirrored content of embedded ones. I don't know whether this was fixed or not

This is a way, thank you

chf007 avatar Aug 17 '21 11:08 chf007

CleanShot 2021-08-17 at 14 35 10@2x This is how I did it

I have the same problem here, is there any other solutions? it seems ugly to use a BeforeInsert and duplicate fields :(

sofia-cloudman avatar Dec 16 '21 08:12 sofia-cloudman