Skip to content

Instantly share code, notes, and snippets.

@fuzzmonkey
Created September 1, 2014 18:09
Show Gist options
  • Save fuzzmonkey/77a0d1065043a5e4e387 to your computer and use it in GitHub Desktop.
Save fuzzmonkey/77a0d1065043a5e4e387 to your computer and use it in GitHub Desktop.
This code generates three SQL queries in ActiveRecord. Not what i was expecting..
foos = Foo.where(params)
if foos.any?
# Foo Load (0.1ms) select count from foos where params
if foos.size == 1 && foos.first.attribute == 'bar'
# Foo Load (0.1ms) select count from foos where params
# Foo Load (0.1ms) select * from foos where params
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment