-
Hi, I am trying to use Here my config: // mikro config
import { MikroORMOptions } from '@mikro-orm/core';
import { MikroNamingStrategy } from './config/mikro';
const config: Partial<MikroORMOptions> = {
type: 'postgresql',
host: process.env.DB_HOST,
user: process.env.DB_USER,
entities: ['./dist/db/models'],
entitiesTs: ['./src/db/models'],
password: process.env.DB_PASSWORD,
namingStrategy: MikroNamingStrategy,
port: parseInt(process.env.DB_PORT, 10),
debug: process.env.NODE_ENV === 'development',
dbName: process.env.DB_NAME || 'ecommerce_development',
seeder: {
glob: '!(*.d).{js,ts}',
path: './dist/db/seeds',
pathTs: './src/db/seeds',
},
migrations: {
path: './dist/db/migrations',
pathTs: './src/db/migrations',
},
};
export default config; // app.module.ts
import { Module } from '@nestjs/common';
import { MikroOrmModule } from '@mikro-orm/nestjs';
@Module({
imports: [
MikroOrmModule.forRoot(),
...
],
...
})
export class AppModule {} // taxons.module.ts
import { Module } from '@nestjs/common';
import { MikroOrmModule } from '@mikro-orm/nestjs';
import { Taxon } from 'db/models/Taxon';
import { TaxonsController } from './taxons.controller';
import { FilterTaxonsService } from './services/FilterTaxonsService';
@Module({
imports: [MikroOrmModule.forFeature([Taxon])],
controllers: [TaxonsController],
providers: [
FilterTaxonsService,
...
],
})
export class TaxonsModule {} // FilterTaxonsService.ts
import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@mikro-orm/nestjs';
import { EntityManager } from '@mikro-orm/postgresql';
// import { EntityManager } from '@mikro-orm/core';
import type { EntityRepository, FilterQuery } from '@mikro-orm/core';
import { Taxon } from 'db/models/Taxon';
import { FilterService } from 'services/generics/FilterService';
import type {
IPagyParams,
IMetadataProps,
} from 'services/generics/FilterService';
interface IFilterParams extends IPagyParams {
name?: string;
}
@Injectable()
export class FilterTaxonsService extends FilterService {
constructor(
@InjectRepository(Taxon)
private readonly taxonRepository: EntityRepository<Taxon>,
private readonly em: EntityManager,
) {
super();
}
public async exec({
name,
page,
perPage,
}: IFilterParams): Promise<[Taxon[], IMetadataProps]> {
let filter: FilterQuery<Taxon> = {};
if (name) {
filter = {
...filter,
name: {
$ilike: name,
},
};
}
const { limit, offset, ...pagyOptions } = this.pagy({
page,
perPage,
});
const [taxons, totalRecords] = await this.taxonRepository.findAndCount(
filter,
{
limit,
offset,
populate: ['parent'],
},
);
return [
taxons,
{
...pagyOptions,
totalRecords,
},
];
}
} |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 23 replies
-
if I use I cannot find a solution from document |
Beta Was this translation helpful? Give feedback.
-
@B4nan sorry for bothering you. But it seems this problem occurs because the
So I think we should have an option for For example we do something like static async forRoot(options?: MikroOrmModuleSyncOptions): Promise<DynamicModule> {
const contextName = this.setContextName(options?.contextName);
const knex = await tryRequire(() => import('@mikro-orm/knex'));
const mongo = await tryRequire(() => import('@mikro-orm/mongodb'));
const driver = (['mongodb', 'knex'].includes(options.driver) || !options.driver) ? null : await tryRequire(() => import(`@mikro-orm/${options.driver}`));
return {
module: MikroOrmCoreModule,
providers: [
{ provide: MIKRO_ORM_MODULE_OPTIONS, useValue: options || {} },
createMikroOrmProvider(contextName),
createEntityManagerProvider(options?.scope, EntityManager, contextName),
...(knex ? [createEntityManagerProvider(options?.scope, knex.SqlEntityManager, contextName)] : []),
...(mongo ? [createEntityManagerProvider(options?.scope, mongo.MongoEntityManager, contextName)] : []),
...(driver ? [createEntityManagerProvider(options?.scope, driver.SqlEntityManager, contextName)] : []),
],
exports: [
contextName ? getMikroORMToken(contextName) : MikroORM,
contextName ? getEntityManagerToken(contextName) : EntityManager,
...(knex ? (contextName ? [] : [knex.SqlEntityManager as any]) : []),
...(mongo ? (contextName ? [] : [mongo.MongoEntityManager as any]) : []),
...(driver ? (contextName ? [] : [driver.SqlEntityManager as any]) : []),
],
};
} |
Beta Was this translation helpful? Give feedback.
-
This problem is solved. I tested with |
Beta Was this translation helpful? Give feedback.
-
sorry for bothering you again. I tried to debug but couldn't find out the issue or solution. I created a package to provide a helper method to init all shared modules that some projects in monorepo will use it. But NestJS always raise Nest can't resolve dependencies of the MikroOrmCoreModule (Symbol(mikro-orm-module-options), ?). Please make sure that the argument ModuleRef at index [1] is available in the MikroOrmCoreModule context.
Potential solutions:
- Is MikroOrmCoreModule a valid NestJS module?
- If ModuleRef is a provider, is it part of the current MikroOrmCoreModule?
- If ModuleRef is exported from a separate @Module, is that module imported within MikroOrmCoreModule?
@Module({
imports: [ /* the Module containing ModuleRef */ ]
}) But if I use the Old version didn't throw this error as I remember |
Beta Was this translation helpful? Give feedback.
This problem is solved. I tested with
@mikro-orm
version6.0.0-dev.15
and@mikro-orm/nestjs
5.1.3