Skip to content

Commit

Permalink
Skip primary key in a more reliable way across rails versions
Browse files Browse the repository at this point in the history
Rails decided to remove Column#primary [1] and this breaks our ability
to detect whether the column is the primary key as we used to, so rely
on the target class' primary key method for that, which should work fine
in all other rails versions.

[1]
rails/rails@05dd3df
  • Loading branch information
carlosantoniodasilva committed Nov 4, 2014
1 parent 0d4a35c commit ae8f9d6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/i18n_alchemy/proxy.rb
Expand Up @@ -69,7 +69,7 @@ def active_record_compatible?
def build_attributes
@target_class.columns.each do |column|
column_name = column.name
next if column.primary || column_name.ends_with?("_id") || @localized_attributes.key?(column_name)
next if skip_column?(column_name)

parser = detect_parser_from_column(column)
build_attribute(column_name, parser)
Expand Down Expand Up @@ -142,6 +142,12 @@ def detect_parser(type_or_parser)
type_or_parser
end
end

def skip_column?(column_name)
column_name == @target_class.primary_key ||
column_name.ends_with?("_id") ||
@localized_attributes.key?(column_name)
end
end
end
end

0 comments on commit ae8f9d6

Please sign in to comment.