Skip to content

Commit

Permalink
Create a join model for request issues and decision issues (#7886)
Browse files Browse the repository at this point in the history
This is the first PR for #7884

### Description
1. Create a join model RequestDecisionIssue and the associated table.
2. Start writing to the new table for HLR and SC as well as to the source_request_issue_id column
  • Loading branch information
Anya Roltsch authored and va-bot committed Nov 16, 2018
1 parent 7f860e0 commit f750a14
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 10 deletions.
1 change: 1 addition & 0 deletions app/models/decision_issue.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
class DecisionIssue < ApplicationRecord
validates :disposition, inclusion: { in: Constants::ISSUE_DISPOSITIONS_BY_ID.keys.map(&:to_s) }, allow_nil: true
# TODO: has_many :request_issues, through: :request_decision_issues
belongs_to :source_request_issue, class_name: "RequestIssue"
end
24 changes: 16 additions & 8 deletions app/models/rating_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,22 @@ def save_decision_issue
# if a DecisionIssue already exists then do not touch it. These should be immutable.
return if decision_issue

DecisionIssue.create!(
source_request_issue: source_request_issue,
rating_issue_reference_id: reference_id,
participant_id: participant_id,
promulgation_date: promulgation_date,
decision_text: decision_text,
profile_date: profile_date
)
ActiveRecord::Base.transaction do
created_decision_issue = DecisionIssue.create!(
source_request_issue: source_request_issue,
rating_issue_reference_id: reference_id,
participant_id: participant_id,
promulgation_date: promulgation_date,
decision_text: decision_text,
profile_date: profile_date
)

RequestDecisionIssue.create!(
request_issue: source_request_issue,
decision_issue: created_decision_issue
)
created_decision_issue
end
end

# If you change this method, you will need to clear cache in prod for your changes to
Expand Down
4 changes: 4 additions & 0 deletions app/models/request_decision_issue.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class RequestDecisionIssue < ApplicationRecord
belongs_to :request_issue
belongs_to :decision_issue
end
1 change: 1 addition & 0 deletions app/models/request_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class RequestIssue < ApplicationRecord

belongs_to :review_request, polymorphic: true
belongs_to :end_product_establishment
# TODO: has_many :decision_issues, through: :request_decision_issues
has_many :decision_issues, foreign_key: "source_request_issue_id"
has_many :remand_reasons
has_many :duplicate_but_ineligible, class_name: "RequestIssue", foreign_key: "ineligible_due_to_id"
Expand Down
9 changes: 9 additions & 0 deletions db/migrate/20181116155733_create_request_decision_issues.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CreateRequestDecisionIssues < ActiveRecord::Migration[5.1]
def change
create_table :request_decision_issues do |t|
t.integer :request_issue_id
t.integer :decision_issue_id
t.timestamps
end
end
end
11 changes: 9 additions & 2 deletions db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20181114142531) do
ActiveRecord::Schema.define(version: 20181116155733) do

# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
Expand Down Expand Up @@ -635,6 +635,13 @@
t.index ["request_issue_id"], name: "index_remand_reasons_on_request_issue_id"
end

create_table "request_decision_issues", force: :cascade do |t|
t.integer "request_issue_id"
t.integer "decision_issue_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end

create_table "request_issues", force: :cascade do |t|
t.string "review_request_type"
t.bigint "review_request_id"
Expand All @@ -654,12 +661,12 @@
t.bigint "ineligible_due_to_id"
t.boolean "untimely_exemption"
t.text "untimely_exemption_notes"
t.string "ineligible_reason"
t.string "ramp_claim_id"
t.datetime "decision_sync_submitted_at"
t.datetime "decision_sync_attempted_at"
t.datetime "decision_sync_processed_at"
t.string "decision_sync_error"
t.string "ineligible_reason"
t.index ["contention_reference_id", "removed_at"], name: "index_request_issues_on_contention_reference_id_and_removed_at", unique: true
t.index ["end_product_establishment_id"], name: "index_request_issues_on_end_product_establishment_id"
t.index ["ineligible_due_to_id"], name: "index_request_issues_on_ineligible_due_to_id"
Expand Down
1 change: 1 addition & 0 deletions spec/models/rating_issue_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@
expect(subject.decision_issue).to be_a(DecisionIssue)
expect(subject.decision_issue.rating_issue_reference_id).to eq(reference_id)
expect(subject.decision_issue.source_request_issue).to eq(request_issue)
expect(RequestDecisionIssue.where(decision_issue: subject.decision_issue).first).to_not be_nil
end

it "does not save duplicates" do
Expand Down

0 comments on commit f750a14

Please sign in to comment.