The original entity is defined as shown below:
import { Entity, PrimaryGeneratedColumn} from "typeorm"
@Entity()
export class Product {
@PrimaryGeneratedColumn()
id: number
The DataSource is initialized with the following code:
import { DataSource } from "typeorm"
import { Cart } from "../entity/Product"
export const AppDataSource = new DataSource({
type: "postgres",
host: "localhost",
port: 5432,
username: "engineerhead",
password: "",
database: "test",
synchronize: true,
logging: false,
entities: [ Product ],
migrations: [],
subscribers: [],
})
export default async () => {
await AppDataSource.initialize();
}
In the setup code, the database is initialized:
import initDB from "./data-source.ts"
await initDB();
Now, a new entity needs to be added at runtime:
import { Entity, PrimaryGeneratedColumn} from "typeorm"
@Entity()
export class Cart{
@PrimaryGeneratedColumn()
id: number
I attempted to retrieve the entities' array from the options object but found it to be read-only:
import AppDataSource from "./data-source"
const ents = AppDataSource.options.entities;
Is there a way to add 'Cart' to the DataSource's entities array at runtime after it has been initialized?