Howdy! I have this in my db: ```User { groups: [...
# mongodb
d
Howdy! I have this in my db:
Copy code
User {
  groups: [{
    groupId: 'group1-id',
    membershipType: 'Member'
  }, {
    groupId: 'group2-id',
    membershipType: 'Admin'
  }]
}
I want
User.groups.groupId
to be a relation. It’s currently not possible to set relationships on composite types. Is there any workaround around this? Any better way to attach some attribute to a relationship?
👀 1
a
Hey Dmitri! Could you share what you current Prisma schema looks like? Do you have to use a composite type or can you convert it to a full model so that you can use relations?
d
I’m sorry @Austin , missed your reply! It’s modelled like a composite type:
Copy code
type GroupMembership {
  communityId String            @db.ObjectId
  role        GroupUserRole
}
model User {
  groups GroupMembership[]
}
What do you mean by full model? If you mean a separate collection, then no, we’d rather not do that, as it’s not really a Mongo way for modelling such things.
a
I think using a relation between `model`’s is the only way forward, as of now. You could try to maintain the data integrity manually, but that’s usually inadvisable. We have any outstanding feature request for relations in composite types, it would be great if you could add your use case. It really helps our engineers!
v
👋 Hello @Dmitri Pisarev, did you have a chance to check Austin's suggestion? Please us know if you have any comments or questions!