1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Add AbstractAdapter#table_alias_for to create table aliases according to the rules of the current adapter. [Rick]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3916 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
This commit is contained in:
Rick Olson 2006-03-18 05:43:35 +00:00
parent 459559a8bc
commit 263479b5a3
7 changed files with 43 additions and 0 deletions

View file

@ -1,5 +1,7 @@
*SVN*
* Add AbstractAdapter#table_alias_for to create table aliases according to the rules of the current adapter. [Rick]
* Provide access to the underlying database connection through Adapter#raw_connection. Enables the use of db-specific methods without complicating the adapters. #2090 [Koz]
* Remove broken attempts at handling columns with a default of 'now()' in the postgresql adapter. #2257 [Koz]

View file

@ -8,6 +8,20 @@ module ActiveRecord
{}
end
# This is the maximum length a table alias can be
def table_alias_length
255
end
# Truncates a table alias according to the limits of the current adapter.
def table_alias_for(table_name, index = 1)
if index > 1
"#{table_name[0..table_alias_length-3]}_#{index}"
else
table_name[0..table_alias_length-1]
end
end
# def tables(name = nil) end
# Returns an array of indexes for the given table.

View file

@ -188,6 +188,10 @@ begin
def reconnect!
end
def table_alias_length
128
end
private
def with_statement

View file

@ -191,6 +191,9 @@ begin
}
end
def table_alias_length
30
end
# QUOTING ==================================================
#

View file

@ -101,6 +101,9 @@ module ActiveRecord
true
end
def table_alias_length
63
end
# QUOTING ==================================================

View file

@ -150,6 +150,10 @@ module ActiveRecord
# connect! # Not yet implemented
end
def table_alias_length
30
end
# Check for a limit statement and parse out the limit and
# offset if specified. Remove the limit from the sql statement
# and call select.

View file

@ -46,6 +46,19 @@ class AdapterTest < Test::Unit::TestCase
end
end
def test_table_alias
old = @connection.table_alias_length
def @connection.table_alias_length() 10; end
assert_equal 'posts', @connection.table_alias_for('posts')
assert_equal 'posts', @connection.table_alias_for('posts', 1)
assert_equal 'posts_2', @connection.table_alias_for('posts', 2)
assert_equal 'posts_comm', @connection.table_alias_for('posts_comments')
assert_equal 'posts_co_2', @connection.table_alias_for('posts_comments', 2)
def @connection.table_alias_length() old; end
end
# test resetting sequences in odd tables in postgreSQL
if ActiveRecord::Base.connection.respond_to?(:reset_pk_sequence!)
require 'fixtures/movie'