Skip to content
This repository was archived by the owner on Jan 14, 2021. It is now read-only.
This repository was archived by the owner on Jan 14, 2021. It is now read-only.

create OR connect on nested writes (upsert) #336

@johanmic

Description

@johanmic

is there a plan to add an upsert to nested writes? The use case is when you dont know if the nested record exists or not

say im creating a movie with a list of n actors, some already exist and some do not.
using either create or connect wont work since i dont know beforehand which exist or not.

the only current solution is to loop and upsert the entire list and then always use connect.
so instead of connect, create also add an upsert

(pseudo ish)

const actors = [{name:'Johnny Dopp'}, {name:'Brad Pitts'}]

const actorIds = Promise.all(actors.map((actor)=>photon.artists.upsert({
    where: { name: actor.name },
    update: {},
    create: actor
  }))

photon.movie.create({
    name: "something",
    cast: {
      connect: actorIds.map(actor=>actor.id)
    }
  })

but instead

photon.movie.create({
    name: "something",
    cast: {
      upsert: [ 
          {name:'Johnny Dopp'}, 
          {name:'Brad Pitts'}
      ]
    }
  })

the first one is not very ACID obviously.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions