Hello guys,
I have a location model that have a parent location field. In other terms, a location can have a parent location and can have multiples child locations. There is a belongTo and hasMany relationship defined here.
Location.associate = (models) => {
Location.belongsTo(models.location, {
foreignKey: {
name: 'parentIdKey',
field: 'parent_id',
},
as: 'parent',
});
Location.hasMany(models.location, {
foreignKey: {
name: 'parentIdKey',
field: 'parent_id',
},
as: 'parentLocations',
});
}
I want when editing or creating a location, to only populate as a parent location, locations meeting specific criteria.
Thank for your help!