Skip to content
Open
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
7 changes: 6 additions & 1 deletion lib/cequel/record/orm_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def get(key_values)
# none present
#
def find_first(options = {})
construct_scope(options).first
scope = construct_scope(options)
if scope.is_a?(Record)
scope.exists? ? scope : nil
else
scope.first
end
end

#
Expand Down
10 changes: 10 additions & 0 deletions spec/examples/orm_adapter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,16 @@
post_adapter.find_first(conditions: {blog_subdomain: 'postgres'})
.should == other_post
end

it 'should find first when there is only a single record present' do
expect(blog_adapter.find_first(conditions: { subdomain: 'cassandra' }))
.to eq(blog)
end

it 'should return nil if no record could be found' do
expect(blog_adapter.find_first(conditions: { subdomain: 'nope' }))
.to be_nil
end

it 'should find first with secondary index condition' do
post_adapter.find_first(conditions: {author_id: 1})
Expand Down