Created
November 30, 2011 19:54
-
-
Save kjg/1410534 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Patch for rails 3.1 below | |
# For master s/connection_pool/connection.schema_cache/ | |
module ActiveRecord | |
class Base | |
class << self | |
... | |
def columns | |
if defined?(@primary_key) | |
if connection_pool.columns.has_key?(table_name) && connection_pool.primary_keys[table_name].nil? | |
connection_pool.columns.delete table_name | |
connection_pool.columns_hash.delete table_name | |
end | |
connection_pool.primary_keys[table_name] ||= primary_key | |
end | |
connection_pool.columns[table_name] | |
end | |
... | |
end | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## must run activerecord's `rake postgresql:build_databases` | |
require 'active_record' | |
ActiveRecord::Base.establish_connection(:adapter => 'postgresql', :database => 'activerecord_unittest') | |
ActiveRecord::Schema.define do | |
execute <<_SQL | |
CREATE SEQUENCE foo_seq; | |
CREATE TABLE posts( | |
foo int NOT NULL DEFAULT nextval( 'foo_seq'::regclass ) | |
); | |
_SQL | |
end | |
class Post < ActiveRecord::Base | |
self.primary_key = :foo | |
end | |
begin | |
p Post.create | |
p Post.primary_key | |
ensure | |
ActiveRecord::Base.connection.execute <<_SQL | |
DROP TABLE posts; | |
DROP SEQUENCE foo_seq; | |
_SQL | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment