Deleting resources that have existing relationships
Version info:
So I have a Ash Postgres resource, lets call it
Car
.
I also have another Ash Postgres resource called CarLog
.
Whenever a change happens to Car
a CarLog
with the nature of the change is created. (so 1:many relation between Car
:CarLog
)
However if a resource instance of Car
is deleted I don't want to delete and of the CarLog
s associated with it.
In my CarLog
resource I have:
To my understanding this should make it possible to destroy a Car
resource instance, and leave the associated CarLog
s behind?
However, when I try to delete a Car
with existing CarLog
s I'm getting this error:
I've found the source of the error in ash_postgres
, and seems to because it doesn't meet a foreign key constraint:
https://github.com/ash-project/ash_postgres/blob/0ad06c6b636c4b4d3ff66971ddde68828d446667/lib/data_layer.ex#L1484-L1485
What do I need to do to allow the destruction of resources instances that have references to others?6 Replies
In case you need it here is the constraint specified in the migration:
You probably want
on_delete: :nilify
🙂Wow and just like that it works!
Thanks @Zach Daniel!
My pleasure 😄
How do I mark as solved?
already done 😆
but you'd right click the channel in the left and add the solved tag
and then close it
kind of inconvenient. I'd like to make our bot do it, where if your post is tagged with solved it gets closed automatically