Last active
January 3, 2016 12:39
-
-
Save olvap/8464061 to your computer and use it in GitHub Desktop.
ActiveForce refactor.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Account < ActiveForce::SObject | |
| ... | |
| has_many :medications, | |
| where: "(Date_Discontinued__c > #{ Date.today.strftime("%Y-%m-%d") } or Date_Discontinued__c = NULL)" | |
| ... | |
| end | |
| class PortalUser < ActiveRecord::Base | |
| ... | |
| def medications | |
| @medications ||= account.medications | |
| end | |
| ... | |
| end | |
| class Medication < ActiveForce::SObject | |
| ... | |
| field :account_id, from: 'Account' | |
| table_name = 'Patient_Medication__c' | |
| ... | |
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PortalUser < ActiveRecord::Base | |
| def medications | |
| @medications ||= find_medications.map do |sobject| | |
| Medication.build sobject | |
| end if account_id? | |
| end | |
| def find_medications | |
| Client.query(<<-SOQL.strip_heredoc).first.Patient_Medications__r.to_a | |
| SELECT Id, | |
| (SELECT #{Medication.mappings.values.join(', ')} FROM Patient_Medications__r | |
| WHERE Date_Discontinued__c > #{ Date.today.strftime("%Y-%m-%d") } or Date_Discontinued__c = NULL) | |
| FROM Account | |
| WHERE Id = '#{account_id}' | |
| SOQL | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment