Skip to content

@kjg /active_record_base_fix.rb
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
# 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
## 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
Something went wrong with that request. Please try again.