mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Require EnterpriseRole.belongs_to by default
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class EnterpriseRole < ApplicationRecord
|
||||
self.belongs_to_required_by_default = true
|
||||
|
||||
belongs_to :user, class_name: "Spree::User"
|
||||
belongs_to :enterprise
|
||||
|
||||
validates :user, :enterprise, presence: true
|
||||
validates :enterprise_id,
|
||||
uniqueness: { scope: :user_id, message: I18n.t(:enterprise_role_uniqueness_error) }
|
||||
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class RequireUserAndEnterpriseOnEnterpriseRole < ActiveRecord::Migration[7.0]
|
||||
def change
|
||||
change_column_null :enterprise_roles, :user_id, false
|
||||
change_column_null :enterprise_roles, :enterprise_id, false
|
||||
end
|
||||
end
|
||||
@@ -175,8 +175,8 @@ ActiveRecord::Schema[7.0].define(version: 2023_08_09_201542) do
|
||||
end
|
||||
|
||||
create_table "enterprise_roles", id: :serial, force: :cascade do |t|
|
||||
t.integer "user_id"
|
||||
t.integer "enterprise_id"
|
||||
t.integer "user_id", null: false
|
||||
t.integer "enterprise_id", null: false
|
||||
t.boolean "receives_notifications", default: false
|
||||
t.index ["enterprise_id", "user_id"], name: "index_enterprise_roles_on_enterprise_id_and_user_id", unique: true
|
||||
t.index ["enterprise_id"], name: "index_enterprise_roles_on_enterprise_id"
|
||||
|
||||
Reference in New Issue
Block a user