Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ids method AF query #94

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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