I'm applying TypeORM with DDD on a Node.JS project with Typescript.
I'm using "transformer" property of "EntitySchema" to map my entity properties to persistence columns. But I can't find the way to do this with one custom type property that must be mapped to two columns instead of one.
This is an example.
This is my model:
export default class User {
public constructor(public id: UuidValueObject, public name: PersonName, public address: Address) {}
}
All properties are Value Objects that have 1 property, except "address" that has multiple properties (address, postalCode, etc).
This is my EntitySchema that maps properties to persistence model:
export const UserEntity = new EntitySchema<User>({
name: "User",
tableName: "users",
target: User,
columns: {
id: {
type: String,
primary: true,
transformer: {
to: (value: UuidValueObject): string => value.id.toString(),
from: (value: string): UuidValueObject => UuidValueObject.create(value)
}
},
name: {
type: String,
nullable: true,
transformer: {
to: (value: PersonName): any => value.toString(),
from: (value: any): PersonName => PersonName.create(value)
}
}
}
});
My question is, how can I add "address" model property to "columns" property of my EntitySchema in the form of multiple distinct columns?
Many thanks.