Hi,
I've a schema that has a type:
@Prop({ type: [{ type: mongoose.Schema.Types.ObjectId, ref: 'Role' }], }) @ValidateNested({ each: true }) roles: mongoose.Schema.Types.ObjectId[];
The Role schema has some fields and a "special" one, abilities:
@Prop({ type: Array<{ type: RoleAbility }>, default: [] }) @ValidateNested({ each: true }) abilities: [RoleAbility];
Where RoleAbility is an object with 2 strings.
Is there a way I can use populate('roles', 'abilities') and merge them?
Currently I get:
"roles": [ { "abilities": [ { "action": "manage", "module": "all" } ], }, { "abilities": [ { "action": "create", "module": "account" }, { "action": "create_sub", "module": "account" }, { "action": "update", "module": "account" }, ], } ]
and I'd like to get all elements concatenated and without the abilities key name:
"roles": [ { "action": "manage", "module": "all" }, { "action": "create", "module": "account" }, { "action": "create_sub", "module": "account" }, { "action": "update", "module": "account" } ]
Is this possible with ref or will I have to use a virtual or a post hook?
Ty