Skip to content

Commit

Permalink
Add ids method AF query (#94)
Browse files Browse the repository at this point in the history
* SAL-3248 | FEATURE | Add ids method AF query objects

* SAL-3248 v2

* add entry to changelog

---------

Co-authored-by: Joshua Flack <jflack@beyondfinance.com>
  • Loading branch information
cdelpone-beyond-finance and jflack-bf authored May 31, 2024
1 parent be44e31 commit 25c1f96
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 4 additions & 0 deletions lib/active_force/active_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
6 changes: 6 additions & 0 deletions spec/active_force/active_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 25c1f96

Please sign in to comment.