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) 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/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)