Skip to content

Instantly share code, notes, and snippets.

@shuujii
Created April 30, 2012 06:39
Show Gist options
  • Save shuujii/2556038 to your computer and use it in GitHub Desktop.
Save shuujii/2556038 to your computer and use it in GitHub Desktop.
ActiveRecord SQLite3 adapter with foreign key
module ActiveRecord
class Base
class << self
def sqlite3_connection_with_foreign_key(config)
sqlite3_connection_without_foreign_key(config).tap do |db|
db.execute("PRAGMA foreign_keys = ON") if config[:foreign_key]
end
end
alias_method_chain :sqlite3_connection, :foreign_key
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment