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

feat(core): add EntityRepository.getEntityName() method #4745

Merged
merged 3 commits into from
Sep 25, 2023

Conversation

ruscon
Copy link
Contributor

@ruscon ruscon commented Sep 25, 2023

No description provided.

@@ -286,6 +286,10 @@ export class EntityRepository<T extends object> {
return this._em;
}

getEntityName(): EntityName<T> {
return this.entityName;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should always return string here? the type could stay the same for better inference support

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to return Constructor<T>, but I understand this is not possible now :)

Copy link
Contributor Author

@ruscon ruscon Sep 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t know what cases other people will have.

Those who need a string can use Utils.className(this.getRepository().getEntityName())

or we could implement this as an additional proxy method in the EntityRepository

getEntityClassName(): string {
  return Utils.className(this.getEntityName())
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to be entity name, so I think a string is actually what most people would expect. While we accept both string name and class reference, the getters should be consistent in what they return.

If you need the class reference, you can always get that from the metadata, e.g. em.getMetadata('Foo').class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, done

@codecov
Copy link

codecov bot commented Sep 25, 2023

Codecov Report

Patch coverage is 100.00% of modified lines.

❗ Current head fb8d34b differs from pull request most recent head 3c5e1cc. Consider uploading reports for the commit 3c5e1cc to get more accurate results

Files Changed Coverage
packages/core/src/entity/EntityRepository.ts 100.00%

📢 Thoughts on this report? Let us know!.

@ruscon
Copy link
Contributor Author

ruscon commented Sep 25, 2023

Please make a new npm version when you have time. I want to test it. Thanks.

@B4nan
Copy link
Member

B4nan commented Sep 25, 2023

every commit to master is published to npm as dev version

@B4nan B4nan changed the title refactor: add EntityRepository.getEntityName() method feat(core): add EntityRepository.getEntityName() method Sep 25, 2023
@B4nan B4nan merged commit 47bfedd into mikro-orm:master Sep 25, 2023
11 checks passed
@ruscon ruscon deleted the add-repository-get-entity-name branch September 25, 2023 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants