[BugFix] Fix Users not deletable because of foreign key reference (#300)
Fixes #297
This commit is contained in:
parent
274ad381cb
commit
cbf2d27b6b
3 changed files with 9 additions and 2 deletions
|
@ -24,6 +24,7 @@ class User < ApplicationRecord
|
||||||
|
|
||||||
belongs_to :account
|
belongs_to :account
|
||||||
belongs_to :inviter, class_name: 'User', required: false
|
belongs_to :inviter, class_name: 'User', required: false
|
||||||
|
has_many :invitees, class_name: 'User', foreign_key: 'inviter_id', dependent: :nullify
|
||||||
|
|
||||||
has_many :assigned_conversations, foreign_key: 'assignee_id', class_name: 'Conversation', dependent: :nullify
|
has_many :assigned_conversations, foreign_key: 'assignee_id', class_name: 'Conversation', dependent: :nullify
|
||||||
has_many :inbox_members, dependent: :destroy
|
has_many :inbox_members, dependent: :destroy
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
class UpdateUserInviteForeignKey < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
remove_foreign_key :users, column: :inviter_id
|
||||||
|
add_foreign_key :users, :users, column: :inviter_id, on_delete: :nullify
|
||||||
|
end
|
||||||
|
end
|
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema.define(version: 2019_11_24_091232) do
|
ActiveRecord::Schema.define(version: 2019_11_26_185833) do
|
||||||
|
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -224,5 +224,5 @@ ActiveRecord::Schema.define(version: 2019_11_24_091232) do
|
||||||
|
|
||||||
add_foreign_key "contact_inboxes", "contacts"
|
add_foreign_key "contact_inboxes", "contacts"
|
||||||
add_foreign_key "contact_inboxes", "inboxes"
|
add_foreign_key "contact_inboxes", "inboxes"
|
||||||
add_foreign_key "users", "users", column: "inviter_id"
|
add_foreign_key "users", "users", column: "inviter_id", on_delete: :nullify
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue