Skip to content

Instantly share code, notes, and snippets.

@tadman
Created May 25, 2009 18:24
Show Gist options
  • Save tadman/117653 to your computer and use it in GitHub Desktop.
Save tadman/117653 to your computer and use it in GitHub Desktop.
def self.each(key_column = :id, &block)
connection.select_values("SELECT `#{key_column}` FROM `#{table_name}`").each do |key|
begin
yield(find(key))
rescue ActiveRecord::RecordNotFound
# Ignore records which may have been deleted between the time the
# list is created and the record is fetched.
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment