From 984b3931ee37bd7328fb927794fe1048cde1ebe0 Mon Sep 17 00:00:00 2001 From: IJ Kim Date: Sat, 16 Mar 2019 11:04:43 -0400 Subject: [PATCH] selecting the latest subscription if there are multiple subscriptions of the same service --- lib/sf/account.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/sf/account.rb b/lib/sf/account.rb index 21c4e7a..f4b0c5d 100644 --- a/lib/sf/account.rb +++ b/lib/sf/account.rb @@ -133,13 +133,11 @@ def self.active_inc_parts(service_name) private def subscriptions - Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\'") - end - - def subscription_names - subscriptions.map{|s| s.Service__r.Name} + # sorting by Service_Start_Date__c in case of multiple subscriptions of the same service + Sf.client.query("select Service__r.Id, Service__r.Name, Service_Start_Date__c, Service_End_Date__c from Service_Institution__c where Supporting_Institution__c = \'#{self.Id}\' ORDER BY Service_Start_Date__c") end + # The latest subscription is included only in case of the multiple subscriptions of the same service. def start_dates_by_subscription start_dates = {} subscriptions.each {|s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c}