Active Record Queries Resource - department-of-veterans-affairs/caseflow GitHub Wiki

Here is a consolidated guide resource for Active Record Queries. Also check out Rails Console Code Snippets.

Rails Console

UAT

ssm certification uat auto
sudo su -c "source /opt/caseflow-certification/caseflow-certification_env.sh; cd /opt/caseflow-certification/src; bin/rails c"

Prod

ssm certification prod auto
sudo su -c "source /opt/caseflow-certification/caseflow-certification_env.sh; cd /opt/caseflow-certification/src; bin/rails c"

Appeals

View appeal tree

Code snippet
RequestStore[:current_user] = User.system_user
uuid  = "" # Add uuid here
appeal = Appeal.find_by(uuid: uuid)
appeal.treee # Prints out appeal tree

Post-decision motions

All vacate streams for an appeal have the same docket number. Therefore, to find the post-decision motions related to that docket number:

Code snippet
appeal = Appeal.find_by_uuid(uuid)
PostDecisionMotion.where(appeal: Appeal.where(stream_docket_number: appeal.docket_number).all)

Alternatively, if you know you have the original appeal and specifically want post-decision motions started from that appeal:

Code snippet
appeal = Appeal.find_by_uuid(uuid)
PostDecisionMotion.where(task: appeal.tasks)

Legacy appeals

Searching VACOLS by docket number

Code snippet
cases = VACOLS::Case.joins(:folder).where("folder.tinum": docket_number)
vacols_ids = cases.map(&:id)
legacy_appeals = LegacyAppeal.where(vacols_id: vacols_ids)

Factories

Invoking a factory locally

Code snippet
FactoryBot.create(:NAME_OF_FACTORY)
#example 
FactoryBot.create(:bgs_attorney)

Users

Finding a Caseflow user

Code snippet

If you know the user's CSS ID, this find-by method takes care of the upper-casing:

User.find_by_css_id("bvaaabshire")

If you only know their name, and perhaps aren't sure of their formal first name, use LIKE or case-insensitive ILIKE to get a list of possible matches:

User.where("full_name ILIKE '% abshire'")
User.where("full_name ILIKE 'jo% smith'")

Intake Queries

See Intake Bat Team Training

⚠️ **GitHub.com Fallback** ⚠️