mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Require EnterpriseRelationship.belongs_to by default
This commit is contained in:
@@ -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')
|
||||
|
||||
@@ -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
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user