-
-
Notifications
You must be signed in to change notification settings - Fork 610
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
I am encountering an issue with Mikro-ORM where the entity generator does not automatically create the relationship properties between Users and Licenses. Although I have defined the relationship in the database schema, the entities generated do not reflect this relationship as expected
Reproduction
import { MsSqlDriver, Options } from '@mikro-orm/mssql';
import { TsMorphMetadataProvider } from '@mikro-orm/reflection';
import dotenv from 'dotenv';
dotenv.config();
const config: Options = {
driver: MsSqlDriver,
host: process.env.DB_HOST,
port: 1433,
user: process.env.DB_USER,
password: process.env.DB_PASS,
dbName: process.env.DB_NAME,
entities: ['dist/entities/**/*.js'],
entitiesTs: ['src/entities/**/*.ts'],
discovery: {
warnWhenNoEntities: false,
},
metadataProvider: TsMorphMetadataProvider,
baseDir: process.cwd(),
debug: true,
};
export default config;// scripts/generate-entities.ts
import { MikroORM } from '@mikro-orm/core';
import { EntityGenerator } from '@mikro-orm/entity-generator';
import config from '../src/config/mikro-orm.config';
const generateEntities = async () => {
const orm = await MikroORM.init({
...config,
discovery: { warnWhenNoEntities: false },
extensions: [EntityGenerator],
});
const dump = await orm.entityGenerator.generate({
save: true,
path: process.cwd() + '/src/entities',
bidirectionalRelations: true,
});
await orm.close(true);
};
generateEntities().catch((err) => {
console.error(err);
process.exit(1);
});@Entity({ tableName: 'Users' })
export class Users {
@PrimaryKey({ fieldName: 'UserID' })
UserID!: number;
@Property({ fieldName: 'Username', length: 255 })
Username!: string;
}
@Entity({ tableName: 'Licenses' })
export class Licenses {
@PrimaryKey({ fieldName: 'LicenseID' })
LicenseID!: number;
@ManyToOne({ entity: () => Users, fieldName: 'UserID', index: '<Index_License_UserID>' })
UserID!: Users;
}What driver are you using?
@mikro-orm/mssql
MikroORM version
^6.2.9
Node.js version
v22.3.0
Operating system
Windows 11
Validations
- Read the Contributing Guidelines.
- Read the docs.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Slack.
- The provided reproduction is a minimal reproducible example of the bug.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working