From a7d57563a4887c9376257d8202017b5d8772fc85 Mon Sep 17 00:00:00 2001 From: Christina Delpone Date: Fri, 24 May 2024 18:22:30 -0600 Subject: [PATCH 1/3] SAL-3248 | FEATURE | Add ids method AF query objects --- lib/active_force/query.rb | 4 ++++ spec/active_force/query_spec.rb | 7 +++++++ 2 files changed, 11 insertions(+) diff --git a/lib/active_force/query.rb b/lib/active_force/query.rb index aa0072e..fcaf35c 100644 --- a/lib/active_force/query.rb +++ b/lib/active_force/query.rb @@ -107,6 +107,10 @@ def sum field clone_and_set_instance_variables(query_fields: ["sum(#{field})"]) end + def ids + clone_and_set_instance_variables(query_fields: ["Id"]) + end + protected def and_conditions "(#{@conditions.join(') AND (')})" unless @conditions.empty? diff --git a/spec/active_force/query_spec.rb b/spec/active_force/query_spec.rb index 0345ab7..d7711cb 100644 --- a/spec/active_force/query_spec.rb +++ b/spec/active_force/query_spec.rb @@ -236,4 +236,11 @@ expect(query.where("name = 'cool'").sum(:field1).to_s).to eq "SELECT sum(field1) FROM table_name WHERE (name = 'cool')" end end + + describe ".ids" do + it "should return the query for plucking the ids" do + query_with_ids = query.where("name = 'cool'").ids + expect(query_with_ids.to_s).to eq "SELECT Id FROM table_name WHERE (name = 'cool')" + end + end end From 3f223ea08aaffda4016ef2106880ea53dc7d6b93 Mon Sep 17 00:00:00 2001 From: Christina Delpone Date: Tue, 28 May 2024 09:39:33 -0600 Subject: [PATCH 2/3] SAL-3248 v2 --- lib/active_force/active_query.rb | 4 ++++ lib/active_force/query.rb | 4 ---- spec/active_force/active_query_spec.rb | 6 ++++++ spec/active_force/query_spec.rb | 7 ------- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/lib/active_force/active_query.rb b/lib/active_force/active_query.rb index fdb5948..ad00cca 100644 --- a/lib/active_force/active_query.rb +++ b/lib/active_force/active_query.rb @@ -83,6 +83,10 @@ def select *selected_fields super *selected_fields end + def ids + clone_and_set_instance_variables(query_fields: ["Id"]) + end + def find!(id) result = find(id) raise RecordNotFound.new("Couldn't find #{table_name} with id #{id}", table_name, id: id) if result.nil? diff --git a/lib/active_force/query.rb b/lib/active_force/query.rb index fcaf35c..aa0072e 100644 --- a/lib/active_force/query.rb +++ b/lib/active_force/query.rb @@ -107,10 +107,6 @@ def sum field clone_and_set_instance_variables(query_fields: ["sum(#{field})"]) end - def ids - clone_and_set_instance_variables(query_fields: ["Id"]) - end - protected def and_conditions "(#{@conditions.join(') AND (')})" unless @conditions.empty? diff --git a/spec/active_force/active_query_spec.rb b/spec/active_force/active_query_spec.rb index 38fdec9..763e880 100644 --- a/spec/active_force/active_query_spec.rb +++ b/spec/active_force/active_query_spec.rb @@ -117,6 +117,12 @@ def self.decorate(records) end end + describe '#ids' do + it 'returns a query that selects only the Id field' do + expect(active_query.where(field: 123).ids.to_s).to eq "SELECT Id FROM table_name WHERE (Field__c = 123)" + end + end + describe "condition mapping" do it "maps conditions for a .where" do new_query = active_query.where(field: 123) diff --git a/spec/active_force/query_spec.rb b/spec/active_force/query_spec.rb index d7711cb..0345ab7 100644 --- a/spec/active_force/query_spec.rb +++ b/spec/active_force/query_spec.rb @@ -236,11 +236,4 @@ expect(query.where("name = 'cool'").sum(:field1).to_s).to eq "SELECT sum(field1) FROM table_name WHERE (name = 'cool')" end end - - describe ".ids" do - it "should return the query for plucking the ids" do - query_with_ids = query.where("name = 'cool'").ids - expect(query_with_ids.to_s).to eq "SELECT Id FROM table_name WHERE (name = 'cool')" - end - end end From e440edeba14e5fced8641c895a6939cd1acda739 Mon Sep 17 00:00:00 2001 From: Joshua Flack Date: Fri, 31 May 2024 11:00:56 -0400 Subject: [PATCH 3/3] add entry to changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3224fb2..29205ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Not released +- Add `ids` method to ActiveQuery interface (https://github.com/Beyond-Finance/active_force/pull/94) + ## 0.21.1 - Fixes #91. Applies scopes to eager-loaded associations when they are nested. (https://github.com/Beyond-Finance/active_force/pull/92)