Is there a way to set up a relation with a table u...
# prisma-client
s
Is there a way to set up a relation with a table using a non-unique key? Trying to find a way to avoid writing this as two separate queries and I don't have say in changing the existing database.
Copy code
const entityStates = await this.prisma.entityState.findMany({
    select: { id: true, entityTypeID: true },
    where: {
        name: state
    }
})


const entityTypes = await this.prisma.entityType.findMany({
    select: { id: true },
    where: {
        name: 'Enrollment',
        id: { in: entityStates.map( state => state.entityTypeID ) }
    }
})
The logic I'm looking for would look something like this
Copy code
const entityTypes = await this.prisma.entityType.findMany({
    select: { id: true },
    where: {
        name: 'Enrollment',
        EntityStates: {
            where: {
                name: state
            }
        }
    }
})
d
hi Sabin. as a prisma newcomer i looked at this as a code challenge — didn’t solve it though… i tried an embedded second query (roughly,
{ in: { await…
) but it was pretty ugly and also the resulting objects, though they thought they were
User
objects (my test case), seemed to be malformed in some way — i wasn’t able to do anything with them
s
Thanks for giving it a look! I played around with it and didn't find a solid way to do it either. Ended up sticking with two queries. Not the end of the world 🙂