Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a join model for request issues and decision issues #7886

Merged
merged 4 commits into from
Nov 16, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 7 additions & 1 deletion app/models/rating_issue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,20 @@ def save_decision_issue
# if a DecisionIssue already exists then do not touch it. These should be immutable.
return if decision_issue

DecisionIssue.create!(
created_decision_issue = DecisionIssue.create!(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably want to wrap the 2 create calls in a transaction

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point sir!

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

# 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just an observation that we haven't consistently used the AR timestamps on our models. I like doing it, and maybe we should formally endorse that pattern system-wide.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I always add these. I think they are useful.

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