Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: should be a single entity key - with 0 as EntityKey #3828

Closed
1 of 2 tasks
AlfaCoder opened this issue Apr 3, 2023 · 0 comments · Fixed by #3830
Closed
1 of 2 tasks

Error: should be a single entity key - with 0 as EntityKey #3828

AlfaCoder opened this issue Apr 3, 2023 · 0 comments · Fixed by #3830

Comments

@AlfaCoder
Copy link

Which @ngrx/* package(s) are the source of the bug?

data

Minimal reproduction of the bug/regression with instructions

any-entity.module.ts

@NgModule({
  providers: [AnyEntityService , AnyEntityDataService],
})
export class AnyEntityModule {
  constructor(
    entityPaginationService: EntityPaginationService,
    entityDataService: EntityDataService,
    dataService: AnyEntityDataService
  ) {
    entityDataService.registerService('AnyEntity', dataService);
    entityPaginationService.registerEntity('AnyEntity');
  }
}

any-entity.service.ts

@Injectable()
export class AnyEntityService {
  private readonly entityServices: EntityServices = inject(EntityServices);

  private readonly entity = this.entityServices.getEntityCollectionService<AnyTypeExample>('AnyEntity');

  delete = (uniquePropertyNumber : number) => this.entity.delete(uniquePropertyNumber);
}

api.module.ts

@NgModule()
export class ApiStateModule {
  public static forRoot(configurationFactory?: () => Configuration): ModuleWithProviders<ApiModule> {
    const providers = [];

    if (configurationFactory) {
      providers.push({ provide: Configuration, useFactory: configurationFactory });
    }

    return { ngModule: ApiStateRootModule, providers };
  }
}

export const entityMetadata: EntityMetadataMap = {
  AnyEntity: {
    selectId: ({ uniquePropertyNumber }: { uniquePropertyNumber: number }) => uniquePropertyNumber,
  }
};

@NgModule({
  imports: [
    AnyEntityModule,
    ApiStateModule,
  ],
})
export class ApiStateRootModule {}

Minimal reproduction of the bug/regression with instructions

If I now call the delete-method with 0 as key this.anyEntityService,delete(0);

I get "Uncaught (inpromise): Error: should be a single entity key" at this point:

bug-allocation_number-0

My quickfix currently is to typecast: delete = (uniquePropertyNumber: number) => this.entity.delete(`${uniquePropertyNumber}`);

Versions of NgRx, Angular, Node, affected browser(s) and operating system(s)

NgRx: ^14.3.3
Angular: ^14.2.12
Node: v16.14.0
Browsers: Edge, Firefox
OS: Windows 10

Other information

No response

I would be willing to submit a PR to fix this issue

  • Yes
  • No
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants