My getter implementation is being changed on load #3900
-
Describe the bug To Reproduce import { Entity, PrimaryKey } from '@mikro-orm/core';
import * as uuid from 'uuid-mongodb';
@Entity({ abstract: true })
export abstract class BaseMongoAggregate<
Id extends string,
>
{
constructor(id: uuid.MUUID = uuid.v4()) {
super();
this._id = id;
}
@PrimaryKey({ type: 'uuid' })
protected _id: uuid.MUUID;
get id(): Id {
return this._id.toString() as Id;
}
protected set id(arg: Id) {
this._id = uuid.from(arg);
} if you debug an instance returned by find an Expected behavior Versions
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 9 replies
-
Right, I know what's happening. The getter is supposed to be defined only for the "serialized primary key", which is a way the ORM handles ObjectId/string duality in mongo (so kinda the same as you are trying, but for ObjectIds). But it is used regardless of how you define the entity, because of how we setup the metadata defaults. |
Beta Was this translation helpful? Give feedback.
Right, I know what's happening. The getter is supposed to be defined only for the "serialized primary key", which is a way the ORM handles ObjectId/string duality in mongo (so kinda the same as you are trying, but for ObjectIds). But it is used regardless of how you define the entity, because of how we setup the metadata defaults.