hi. i’m working with two basic models: Category and Product
Category Model:
const categorySchema = new Schema(
{
parent: xxxxxxxx // how do i set "parent" to be Category or null?
name: { type: String, required: true },
},
{ timestamps: true }
);
Product Model:
const productSchema = new Schema(
{
categories: xxxxxxxxx // how do i set "categories" to be an array of Category? should i import Category interface (see below) or make a ref to Category model?
name: { type: String, required: true }
qty: { type: Number, required: true }
price: { type: Number, required: true }
},
{ timestamps: true }
);
Can you please confirm if my understanding of your use-case is correct? Are you intending to assign the parent field of the category schema to either “category” or “null” by default? If yes then you can use the referencing feature. Sharing the code snippet for reference:
it helps! then i do have to populate, right? do i have a link so i can read how populate works for cases like this? thank you very much, @Kushagra_Kesav !!