Hi! This is first time I am posting here. I am loo...
# orm-help
s
Hi! This is first time I am posting here. I am looking into migrating from mongoose to prisma for a project. There is a particular case where I am saving ids to array as reference. I am unable to find similar examples online and what exist needs changes to the original schema. If anyone here could guide me on as how to achieve this in prisma that would be great. So, the schema looks something like following # UserSchema
Copy code
const UserSchema = new Schema({
    email: {
        type: String,
        lowercase: true,
        required: true
    },
    info: {
        firstName: String,
        lastName: String,
        mobile: String
    },
    apps: [{type: Schema.Types.ObjectId, ref: 'AppList'}]
}, {timestamps: true});

module.exports = User = mongoose.model('user', UserSchema);
# AppSchema
Copy code
const appSchema = new Schema({
    name: {
        type: String,
        lowercase: true,
        unique: true,
        required: true
    },
    description: String,
}, {timestamps: true});
module.exports = AppList = mongoose.model('AppList', appSchema);
n
Hey Santosh 👋 Could you try this schema
Copy code
// This is your Prisma schema file,
// learn more about it in the docs: <https://pris.ly/d/prisma-schema>

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "mongodb"
  url      = env("DATABASE_URL")
}

model User {
  id    String @id @default(auto()) @map("_id") @db.ObjectId
  email String
  info  String
  apps  app[]
}

type app {
  name        String
  description String
  createdAt   DateTime @default(now())
  updatedAt   DateTime @default(now())
}
s
Hey Nurul, thanks for the response, I was actually able to resolve it with many to many relationship example. I issue in my case was when creating the Prisma Schema I was mapping apps to appId and hence it was not populating. I do have a question with the model you posted, With the solution, wouldn't that be a document instead of id saved in User?