Hey all, got a quick question about data fetching....
# orm-help
d
Hey all, got a quick question about data fetching. I have 2 tables, similar but different data. When loading a page I want to load the data from table 1 or table 2 depending on the ID.. is there a way to pass data to
Copy code
await prisma.X.findUnique
with X being the changing variable. OR, is this a database stucture issue and I need to rethink my design?
o
It should work fine:
Copy code
const modelName = id ? "car" : "truck"
await prisma[modelName].findUnique
You might need to add
//@ts-ignore
before it in case you're using typescript though.
n
Based on your id you can determine the model name in your application logic and then appropriately pass the model name. If could be an
if
condition as well Like
Copy code
if(id === 'x'){
    await prisma.x.findUnique()
  }else{
    await prisma.y.findMany()
  }