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

Specify type of ids in a repository with multiple ids #6343

Closed
frbuceta opened this issue Sep 12, 2020 · 3 comments
Closed

Specify type of ids in a repository with multiple ids #6343

frbuceta opened this issue Sep 12, 2020 · 3 comments
Labels

Comments

@frbuceta
Copy link
Contributor

frbuceta commented Sep 12, 2020

Having two properties of type PK/id is not supported by the DefaultCrudRepository.

The specification of DefaultCrudRepository is:

export class DefaultCrudRepository<
  T extends Entity,
  ID,
  Relations extends object = {}
> implements EntityCrudRepository<T, ID, Relations> {
  ...
}

So the problem is that I can only specify the type of a single id and not of both as you can see in the example below.

Example Code:

@model()
class UserHasPermission extends Entity {
  @property({id: true})
  userId: number;
  @property({id: true})
  permissionId: number;

  constructor(data: Partial<UserHasPermission>) {
    super(data);
  }
}
class UserHasPermissionRepository extends DefaultCrudRepository<
  UserHasPermission,
  typeof UserHasPermission.prototype.id         <<<<<----------- Here
> {
  constructor(dataSource: juggler.DataSource) {
    super(UserHasPermission, dataSource);
  }
}

Any solution?

Additional information

Node: darwin x64 14.10.1

I have this in the loopback repository, in a test for a HasAndBelongsToMany relation

Related Issues

See Reporting Issues for more tips on writing good issues

@frbuceta frbuceta added the bug label Sep 12, 2020
@raymondfeng
Copy link
Contributor

raymondfeng commented Sep 12, 2020

In this case, we should have the following id type:

type UserHasPermissionPK = Pick<UserHasPermission, 'userId' | 'permissionId>

But I don't think LoopBack 4 supports composite ids at runtime.

@achrinza
Copy link
Member

Would this be a duplicate of #1830?

@frbuceta
Copy link
Contributor Author

Would this be a duplicate of #1830?

Yes, I am going to close this issue and we move to that one

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

No branches or pull requests

3 participants