Created
January 25, 2012 12:38
-
-
Save ozgun/1676078 to your computer and use it in GitHub Desktop.
globalize3 fix for rails 3.2
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
module ActiveRecord | |
module ModelSchema | |
module ClassMethods | |
def compute_table_name | |
base = base_class | |
if self == Globalize::ActiveRecord::Translation #globalize3 | |
tbl_name = "translations" | |
elsif superclass == Globalize::ActiveRecord::Translation #globalize3 | |
tbl_name = "#{self.parent.table_name.singularize}_translations" | |
elsif self == base | |
if parent < ActiveRecord::Base && !parent.abstract_class? | |
contained = parent.table_name | |
contained = contained.singularize if parent.pluralize_table_names | |
contained += '_' | |
end | |
tbl_name = "#{full_table_name_prefix}#{contained}#{undecorated_table_name(name)}#{table_name_suffix}" | |
else | |
tbl_name = base.table_name | |
end | |
tbl_name | |
end | |
end | |
end | |
end | |
module ActiveRecord | |
module ConnectionAdapters | |
class AbstractMysqlAdapter < AbstractAdapter | |
def columns(table_name, name = nil)#:nodoc: | |
return [] if table_name == "translations"#globalize3 | |
sql = "SHOW FULL FIELDS FROM #{quote_table_name(table_name)}" | |
execute_and_free(sql, 'SCHEMA') do |result| | |
each_hash(result).map do |field| | |
new_column(field[:Field], field[:Default], field[:Type], field[:Null] == "YES", field[:Collation]) | |
end | |
end | |
end | |
end | |
end | |
end | |
module ActiveRecord | |
module ConnectionAdapters | |
class PostgreSQLAdapter < AbstractAdapter | |
def columns(table_name, name = nil) | |
return [] if table_name == "translations"#globalize3 | |
# Limit, precision, and scale are all handled by the superclass. | |
column_definitions(table_name).collect do |column_name, type, default, notnull| | |
PostgreSQLColumn.new(column_name, default, type, notnull == 'f') | |
end | |
end | |
end | |
end | |
end | |
module ActiveRecord | |
module ConnectionAdapters | |
class SQLiteAdapter < AbstractAdapter | |
# Returns an array of +SQLiteColumn+ objects for the table specified by +table_name+. | |
def columns(table_name, name = nil) #:nodoc: | |
return [] if table_name == "translations" #globalize3 | |
table_structure(table_name).map do |field| | |
case field["dflt_value"] | |
when /^null$/i | |
field["dflt_value"] = nil | |
when /^'(.*)'$/ | |
field["dflt_value"] = $1.gsub(/''/, "'") | |
when /^"(.*)"$/ | |
field["dflt_value"] = $1.gsub(/""/, '"') | |
end | |
SQLiteColumn.new(field['name'], field['dflt_value'], field['type'], field['notnull'].to_i == 0) | |
end | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment