You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using NestJS, Microrm with MongoDB. I am trying to map entity <-> dtos for a structure like below.
//microrm entity for Group
@Entity()
export class Group{
@Property()
name:string
@Property()
members: new Collection<User>(this) <-- refers to collection of User entities
}
//microrm entity for User
@Entity()
export class User{
@Property()
name:string
@Property()
groups: new Collection<Group>(this) <-- refers to collection of Group entities that this user is a member
}
My Dtos are like below
//Group Dto
export class GroupDto{
name:string
members: Array<UserDto>=[] <-- refers to UserDto list
}
//User Dto
export class UserDto{
name:string
groups: Array<GroupDto>=[] <-- refers to GroupDto list
}
With class-transfomer I couldn't get this to work properly and then only I found mapper and wanted to give it a try.
Now, when I query from Group's side (say /get/groups) I want the list of GroupDtos but instead of entire GroupDtos.members can I just fill UserDto.member (So that it won't map user.groups to UserDto.groups)
Similarly when I query from User's side (say /get/users), I only want USerDto.groups to return GroupDto list but only with group.name filled (So it won't map circular properties)
The point is, in both of these paths, it only picks the non-circular-referencing properties
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I am using NestJS, Microrm with MongoDB. I am trying to map entity <-> dtos for a structure like below.
My Dtos are like below
With class-transfomer I couldn't get this to work properly and then only I found mapper and wanted to give it a try.
Now, when I query from Group's side (say /get/groups) I want the list of GroupDtos but instead of entire GroupDtos.members can I just fill UserDto.member (So that it won't map user.groups to UserDto.groups)
Similarly when I query from User's side (say /get/users), I only want USerDto.groups to return GroupDto list but only with group.name filled (So it won't map circular properties)
The point is, in both of these paths, it only picks the non-circular-referencing properties
What is the recommended way to handle this?
Beta Was this translation helpful? Give feedback.
All reactions