Hi.
I met a very interesting issue related to destroy-callbacks in apps backed with PostgreSQL database. To check this issue, you can create a new app from scratch using rails new testapp -d postgresql
, then create a new model, let’s name it Message rails g model Message content
and add callbacks
class Message < ApplicationRecord
before_destroy -> {
Rails.logger.debug "before_destroy triggered for message #{id}"
}
after_destroy -> {
Rails.logger.debug "after_destroy triggered for message #{id}"
}
after_destroy_commit -> {
Rails.logger.debug "after_destroy_commit triggered for message #{id}"
broadcast_remove_to "chat_room_#{chat_room.id}_messages"
}
end
then, when you’ll create several records and try to delete using Message.first.destroy
you’ll see no log messages in development.log, like on my screenshot
but … if you do the same using sqlite3 database rails new testapp -d sqlite3
the result will be different
I’ve created an issue, but it was closed, I believe, because of misunderstanding. So, in case if you’ll be able to reproduce this issue, please leave a note here and in GitHub issues