@aid003

Не получается сохранить данные с отношениями через Prisma?

Пытаюсь сохранить данные в бд sqlite но появляется ошибка хотя вроде бы передаю что нужно. Пробывал добавлять name и {} , но не помогло. Подозреваю что сохранять нужно в цикле, но не представляю реализацию.

Express Prisma SQLite3 Insomnia

Сам текст ошибки

actors: [
      'ggg'
    ],
    ~~~~~~~
    url: '/films/Airbuss/1.mp4'
  }
}

Argument actors: Got invalid value 
[
  'ggg'
]
on prisma.createOneVideo. Provided List<String>, expected ActorCreateNestedManyWithoutVideoInput:
type ActorCreateNestedManyWithoutVideoInput {
  create?: ActorCreateWithoutVideoInput | List<ActorCreateWithoutVideoInput> | ActorUncheckedCreateWithoutVideoInput | List<ActorUncheckedCreateWithoutVideoInput>
  connectOrCreate?: ActorCreateOrConnectWithoutVideoInput | List<ActorCreateOrConnectWithoutVideoInput>
  connect?: ActorWhereUniqueInput | List<ActorWhereUniqueInput>
}


Сервис express:

const createVideoToDatabase = await prisma.video.create({
    data: {
      title: title,
      ratingFilm: ratingFilm,
      postersUrl: postersUrl,
      yearCreate: yearCreate,
      countries: countries,
      gendre: gendre,
      content: content,
      ageRestriction: ageRestriction,
      description: description,
      actors: actors,
      url: url,
    },
  });

  res.status(201);
  res.json(createVideoToDatabase);


Схема в призме:

model Video {
  id             Int        @id @default(autoincrement())
  title          String     @unique
  ratingFilm     Float
  postersUrl     String
  yearCreate     Int
  countries      String
  gendre         String
  content        String
  ageRestriction Int
  description    String
  actors         Actor[]
  url            String
  published      Boolean    @default(true)
}

model Actor {
  name String
  videoId Int @unique
  video Video @relation(fields: [videoId], references: [id])
}


И сами данные которые я посылаю через инсомнию:

{
  "title": "среди нас33",
  "ratingFilm": 9.7,
  "postersUrl": "/films/Airbuss/1.png",
  "yearCreate": 2019,
  "countries": "eec uyyt kft",
  "gendre": "Хорор",
  "content": "Любовь самолет вертолет корабль",
  "ageRestriction": 18,
  "description": "Король кокаина, террорист",
  "actors": ["ggg"],
  "url": "/films/Airbuss/1.mp4"
}
  • Вопрос задан
  • 55 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы