Skip to content

Instantly share code, notes, and snippets.

@phinze
Created October 6, 2009 20:14
Show Gist options
  • Save phinze/203366 to your computer and use it in GitHub Desktop.
Save phinze/203366 to your computer and use it in GitHub Desktop.
class Version
named_scope :as_of, lambda { |a_certain_time|
effkay = original_class.versioned_foreign_key
{ :conditions => [
"#{table_name}.version = (
SELECT MAX(vtn.version)
FROM #{table_name} AS vtn
WHERE vtn.#{effkay} = #{table_name}.#{effkay}
AND vtn.updated_at <= ?
)", a_certain_time.to_s(:db) ] }
}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment