Hi everyone! Does anybody know a good example of u...
# orm-help
j
Hi everyone! Does anybody know a good example of using DDD together with Prisma, specially when it comes to related data? Per example, if you have a List with many tasks, how would you upsert/delete tasks from the list using DDD? TypeORM will identify orphan records in a OneToMany relation when doing an insert and you can tell it to automatically remove them, but I have no idea if this is even possible in Prisma. Thanks!
šŸ‘€ 1
n
Hello @Javier Tarazaga Gomez šŸ‘‹ Welcome to our Slack community! prisma cool Can you have a look at the repository in this message? I think this should be useful to you. Can you please elaborate on the orphan records? Are you looking for referential actions which would delete the child records automatically when the parent record is inserted?
j
Hi @Nurul! Thanks for sharing
I am skipping through the repo but there is one thing I can’t manage to find
and is the source of my issue. So in DDD imagine you have a domain list with tasks. Using typeorm, i can simply ā€œremoveā€ a task from the list domain, and then convert that domain into an persisted entity to be used by TypeORM. So TypeORM will detect automatically that the object you are trying to save vs the item already stored in DB, there is a discrepancy, since the one you are trying to save has a missing record that the DB did have. In this case, you can tell TypeORM to simply remove (aka delete) those orphan records and take as source of truth what your domain is actually composed of
I hope makes sense šŸ˜„
Otherwise, if you don’t have that feature what you would need to do woudl be to load the
list
object from the DB, compare the object from the domain vs the one you just loaded, and all the records of
tasks
not available in the Domain you are trying to save, to actually do a
deleteMany
and delete them manually
mainly is a really convenient way to say, hey my domain is my source of truth and update the DB accordingly