Add column Relationship#initiator_account
This commit is contained in:
parent
ee381bdecf
commit
c6db88c8b9
|
@ -22,6 +22,11 @@ class Relationship < ApplicationRecord
|
|||
|
||||
belongs_to :regional_office, inverse_of: :all_relationships
|
||||
|
||||
belongs_to :initiator_account,
|
||||
class_name: 'Account',
|
||||
inverse_of: false,
|
||||
optional: true
|
||||
|
||||
##########
|
||||
# Scopes #
|
||||
##########
|
||||
|
|
|
@ -33,6 +33,9 @@
|
|||
<th scope="col">
|
||||
<%= Relationship.human_attribute_name :regional_office %>
|
||||
</th>
|
||||
<th scope="col">
|
||||
<%= Relationship.human_attribute_name :initiator_account %>
|
||||
</th>
|
||||
<th scope="col"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
@ -47,6 +50,9 @@
|
|||
<%= staff_regional_office_link_or_none \
|
||||
relationship.regional_office %>
|
||||
</td>
|
||||
<td>
|
||||
<%= staff_account_link_or_none relationship.initiator_account %>
|
||||
</td>
|
||||
<td></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
|
|
|
@ -61,6 +61,12 @@
|
|||
<%= staff_regional_office_link_or_none \
|
||||
@person.current_relationship&.regional_office %>
|
||||
</dd>
|
||||
|
||||
<dt><%= Relationship.human_attribute_name :initiator_account %></dt>
|
||||
<dd>
|
||||
<%= staff_account_link_or_none \
|
||||
@person.current_relationship&.initiator_account %>
|
||||
</dd>
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -75,6 +75,7 @@ en:
|
|||
relationship:
|
||||
id: ID
|
||||
regional_office: Regional department
|
||||
initiator_account: Initiator
|
||||
from_date: From date
|
||||
status: Status
|
||||
user:
|
||||
|
|
|
@ -75,6 +75,7 @@ ru:
|
|||
relationship:
|
||||
id: ID
|
||||
regional_office: Региональное отделение
|
||||
initiator_account: Инициатор
|
||||
from_date: Дата начала
|
||||
status: Статус
|
||||
user:
|
||||
|
|
|
@ -329,11 +329,17 @@ private
|
|||
create_table :relationships do |t|
|
||||
t.timestamps null: false
|
||||
|
||||
t.references :person,
|
||||
null: false, index: false, foreign_key: true
|
||||
t.references :person, null: false,
|
||||
index: false,
|
||||
foreign_key: true
|
||||
|
||||
t.references :regional_office,
|
||||
null: false, index: true, foreign_key: true
|
||||
t.references :regional_office, null: false,
|
||||
index: true,
|
||||
foreign_key: true
|
||||
|
||||
t.references :initiator_account, null: true,
|
||||
index: true,
|
||||
foreign_key: { to_table: :accounts }
|
||||
|
||||
t.date :from_date, null: false, index: true
|
||||
|
||||
|
|
|
@ -687,6 +687,7 @@ CREATE TABLE public.relationships (
|
|||
updated_at timestamp(6) without time zone NOT NULL,
|
||||
person_id bigint NOT NULL,
|
||||
regional_office_id bigint NOT NULL,
|
||||
initiator_account_id bigint,
|
||||
from_date date NOT NULL,
|
||||
status public.relationship_status NOT NULL,
|
||||
role public.relationship_role,
|
||||
|
@ -1188,6 +1189,13 @@ CREATE UNIQUE INDEX index_relationships_on_federal_secretary_flag ON public.rela
|
|||
CREATE INDEX index_relationships_on_from_date ON public.relationships USING btree (from_date);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_relationships_on_initiator_account_id; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
CREATE INDEX index_relationships_on_initiator_account_id ON public.relationships USING btree (initiator_account_id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: index_relationships_on_person_id_and_from_date; Type: INDEX; Schema: public; Owner: -
|
||||
--
|
||||
|
@ -1308,6 +1316,14 @@ ALTER TABLE ONLY public.relationships
|
|||
ADD CONSTRAINT fk_rails_100235139c FOREIGN KEY (regional_office_id) REFERENCES public.regional_offices(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: relationships fk_rails_124c042ac0; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
||||
ALTER TABLE ONLY public.relationships
|
||||
ADD CONSTRAINT fk_rails_124c042ac0 FOREIGN KEY (initiator_account_id) REFERENCES public.accounts(id);
|
||||
|
||||
|
||||
--
|
||||
-- Name: people fk_rails_4f02f930eb; Type: FK CONSTRAINT; Schema: public; Owner: -
|
||||
--
|
||||
|
|
|
@ -4,6 +4,7 @@ FactoryBot.define do
|
|||
factory :supporter_relationship, class: Relationship do
|
||||
association :person, factory: :initial_person
|
||||
association :regional_office
|
||||
association :initiator_account, factory: :superuser_account
|
||||
|
||||
sequence :from_date do |n|
|
||||
Date.new rand((10 * n)...(11 * n)), rand(1..12), rand(1..28)
|
||||
|
|
|
@ -18,6 +18,16 @@ RSpec.describe Relationship do
|
|||
end
|
||||
end
|
||||
|
||||
describe '#initiator_account' do
|
||||
it do
|
||||
is_expected.to \
|
||||
belong_to(:initiator_account)
|
||||
.class_name('Account')
|
||||
.inverse_of(false)
|
||||
.optional
|
||||
end
|
||||
end
|
||||
|
||||
describe '#from_date' do
|
||||
it { is_expected.to validate_presence_of :from_date }
|
||||
|
||||
|
|
Reference in New Issue