Skip to content

Instantly share code, notes, and snippets.

@mrpunkin
Created February 4, 2013 22:40
Show Gist options
  • Select an option

  • Save mrpunkin/4710415 to your computer and use it in GitHub Desktop.

Select an option

Save mrpunkin/4710415 to your computer and use it in GitHub Desktop.
arels = [Vote, Comment, Love].collect{|u|
t = u.arel_table
u.select([
t[:created_at].maximum.as("ts"),
t[:photo_id].as("what_id"),
"'Photo' AS what_type"
]).group(t[:photo_id]).arel
}
union = Arel::Nodes::Union.new(arels[0], arels[1])
union.to_sql
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment