If I were to design a child entity for Inventory
, I would include columns for type
, quantity
, and any other relevant information.
Here's an example of how it could be structured:
@Entity()
export class Customer {
@PrimaryGeneratedColumn()
id!: number;
@Column()
name: string;
@OneToMany(type => InventoryItem, item => item.customer)
inventory: InventoryItem[];
}
@Entity()
export class InventoryItem {
@PrimaryGeneratedColumn()
id!: number;
@Column()
type: string;
@Column()
quantity: number;
@ManyToOne(type => Customer, customer => customer.inventory)
customer: Customer;
}
You can then populate the inventory with items like this:
{
name: "Coffee",
inventory: [
{
type: "beans",
quantity: 5
},
{
type: "sugar",
quantity: 10
}
]
}