From a7d57563a4887c9376257d8202017b5d8772fc85 Mon Sep 17 00:00:00 2001 From: Christina Delpone Date: Fri, 24 May 2024 18:22:30 -0600 Subject: [PATCH] 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