Require EnterpriseRelationship.belongs_to by default

This commit is contained in:
Maikel Linke
2023-07-28 15:31:19 +10:00
parent 4b630f187b
commit cb494b84f2
3 changed files with 10 additions and 3 deletions

View File

@@ -1,11 +1,12 @@
# frozen_string_literal: true
class EnterpriseRelationship < ApplicationRecord
self.belongs_to_required_by_default = true
belongs_to :parent, class_name: 'Enterprise', touch: true
belongs_to :child, class_name: 'Enterprise', touch: true
has_many :permissions, class_name: 'EnterpriseRelationshipPermission', dependent: :destroy
validates :parent, :child, presence: true
validates :child_id, uniqueness: {
scope: :parent_id,
message: I18n.t('validation_msg_relationship_already_established')

View File

@@ -0,0 +1,6 @@
class RequireParentAndChildOnEnterpriseRelationship < ActiveRecord::Migration[7.0]
def change
change_column_null :enterprise_relationships, :parent_id, false
change_column_null :enterprise_relationships, :child_id, false
end
end

View File

@@ -167,8 +167,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_09_201542) do
end
create_table "enterprise_relationships", id: :serial, force: :cascade do |t|
t.integer "parent_id"
t.integer "child_id"
t.integer "parent_id", null: false
t.integer "child_id", null: false
t.index ["child_id"], name: "index_enterprise_relationships_on_child_id"
t.index ["parent_id", "child_id"], name: "index_enterprise_relationships_on_parent_id_and_child_id", unique: true
t.index ["parent_id"], name: "index_enterprise_relationships_on_parent_id"