MCPcopy Create free account
hub / github.com/mikro-orm/mikro-orm / getRepository

Method getRepository

packages/core/src/EntityManager.ts:179–190  ·  view source on GitHub ↗

* Gets repository for given entity. You can pass either string name or entity class reference.

(
    entityName: EntityName<Entity>,
  )

Source from the content-addressed store, hash-verified

177 * Gets repository for given entity. You can pass either string name or entity class reference.
178 */
179 getRepository<Entity extends object, Repository extends EntityRepository<Entity> = EntityRepository<Entity>>(
180 entityName: EntityName<Entity>,
181 ): GetRepository<Entity, Repository> {
182 const meta = this.metadata.get(entityName);
183
184 if (!this.#repositoryMap.has(meta)) {
185 const RepositoryClass = this.config.getRepositoryClass(meta.repository) as Constructor<EntityRepository<any>>;
186 this.#repositoryMap.set(meta, new RepositoryClass(this, entityName));
187 }
188
189 return this.#repositoryMap.get(meta) as GetRepository<Entity, Repository>;
190 }
191
192 /**
193 * Shortcut for `em.getRepository()`.

Calls 4

getMethod · 0.65
hasMethod · 0.65
setMethod · 0.65
getRepositoryClassMethod · 0.45

Tested by 2

testMethod · 0.36
requestCommonServiceFunction · 0.36