Skip to content

Instantly share code, notes, and snippets.

@nyarly
Created February 17, 2012 10:27
Show Gist options
  • Save nyarly/1852503 to your computer and use it in GitHub Desktop.
Save nyarly/1852503 to your computer and use it in GitHub Desktop.
Reinventing a wheel? (ActiveRecord)
def self.build_pairs(rel)
require 'pp'
records = connection.select_all(sanitize_sql(rel.to_sql), "#{name} Load Pairs", [])
records.map do |record|
split = record.to_a.map do |key,value|
key.split(".",2) + [value]
end.group_by do |list|
list.first
end.values.map do |record|
instantiate(Hash[record.map{|triple| triple[1..2]}])
end.sort do |l,r|
l.id <=> r.id
end.tap{|split| pp split}
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment