-
-
Notifications
You must be signed in to change notification settings - Fork 611
Closed
Labels
bugSomething isn't workingSomething isn't working
Description
Describe the bug
When using embeddables i get a prefix exception which seems to depend on the order of inclusion of the entities.
Stack trace
(node:64443) UnhandledPromiseRejectionWarning: MetadataError: Property A:b_c_d_test is being overwritten by its child property b_c:b_c_d_test. Consider using a prefix to overcome this issue.
at Function.conflictingPropertyName (/Users/gabriel.b-hansen/git/smule/crumb-server/node_modules/@mikro-orm/core/errors.js:160:16)
at MetadataDiscovery.initEmbeddables (/Users/gabriel.b-hansen/git/smule/crumb-server/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:475:46)
at MetadataDiscovery.initEmbeddables (/Users/gabriel.b-hansen/git/smule/crumb-server/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:513:18)
at Object.values.forEach.prop (/Users/gabriel.b-hansen/git/smule/crumb-server/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:44:86)
at Array.forEach (<anonymous>)
at filtered.forEach.meta (/Users/gabriel.b-hansen/git/smule/crumb-server/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:44:65)
at Array.forEach (<anonymous>)
at MetadataDiscovery.discover (/Users/gabriel.b-hansen/git/smule/crumb-server/node_modules/@mikro-orm/core/metadata/MetadataDiscovery.js:44:18)
at process._tickCallback (internal/process/next_tick.js:68:7)
at Function.Module.runMain (internal/modules/cjs/loader.js:834:11)
To Reproduce
import { Embeddable, Embedded, Entity, MikroORM, OneToOne, PrimaryKey, Property } from "@mikro-orm/core";
require("dotenv").config();
@Embeddable()
export class D {
@Property({type: "boolean", nullable: true})
test?: boolean = false;
}
@Entity()
export class C {
@PrimaryKey()
id: number;
@Embedded(() => D, { object: true, nullable: false })
d!: D;
}
@Embeddable()
export class B {
@Embedded(() => C, {object: true, nullable: false})
c!: C;
@Embedded(() => C, {object: true, nullable: false})
c2!: C;
}
@Entity()
export class A {
@PrimaryKey()
id: number;
@Embedded(() => B, {array: true})
b: B[] = [];
}
let clientUrl = process.env.CLIENT_URL.trim();
let testInitialize = async () => {
const orm = await MikroORM.init({
type: "mongo",
dbName: "smule",
clientUrl: clientUrl,
entities: [
//A, B, C, D, //Passes
C, D, A, B, //Fails
],
debug: false,
});
let a = new A();
let b = new B();
let c = new C();
let c2 = new C();
let d = new D();
c.d = d;
b.c = c;
b.c2 = c2;
a.b.push(b);
await orm.em.persistAndFlush(a);
console.log("DONE");
};
testInitialize();Expected behavior
Its fine if the order does matter, I just haven´t read anywhere that it does.
Versions
| Dependency | Version |
|---|---|
| node | 10.16.3 |
| typescript | 4.2.3 |
| mikro-orm | 4.5.1 |
| your-driver | mongodb (4.5.1) |
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working