if I delete a top node containing nested (connecte...
# orm-help
z
if I delete a top node containing nested (connected) nodes - should I delete the sub-nodes so that they aren't left as "undeserted" ? Are they cleaned up automatically by some health-check script? I am trying to not have to define relationship in SDL, I know using cascade will take care of this... but is it really needed?
a
So you basically have lots of
Copy code
type A {
  b: B @relation(name: "AtoB", onDelete: CASCADE)
  otherField: String
  ...
}

type B { 
  ...
}
And now you want to delete all nodes of type
A
but not necessarily of type
B
?
z
yes but I want to be lazy and not define the @relation (...)
as B is only related to A I was hoping it would be deleted automatically somehow, by some maintenance routine maybe...
a
well if you don't define cascade, how would prisma know that nodes of type `B`should be deleted when nodes of type
A
are deleted? It could very well be that type
B
went from being a subfield to independent data
Example: Due to GDPR, a lot of sensitive data must be removed from a
Person
type and separated from things like contactinfo. So you take the
personalia
field and extract it to its own type which is no longer connected directly to a
Person object
z
it couldn't - but they would not be connected to any node at all
a
That's my point. I'd be very surprised if Prisma suddenly started making decisions like this to data that is not connected
z
hmm... I got enlightened... I was under the impression that connected nodes were different somehow - thanks for clarifying!
a
What do you mean?
z
I'll define all relations in schema from now on!
doesn't matter, just my misunderstanding - but thx again for clarifying!
a
If you want prisma to have some kind of cleanup routine that cleans unreachable data, then your very first datatype would automatically be cleaned up 😛
z
it all started when I read that relationship names don't have to be defined in SDL
so I started removing the @relationship declarations because I thought it was overhead
a
Ah
I can see that. You assumed that on-cascade-delete was the default?
z
exactly!
also bothers my that to defined delete action I have to create a name for the relation
@relation(name: "Comments", onDelete: CASCADE)
maintaining these names was becoming a tedious task for a schema in creation
a
Hmm. I think I'm confused by the docs as well here
This argument is only required if relations are ambiguous. Note that the name argument is required every time you're using the @relation directive.
z
agree - "you can skip it but still you need it"