nil exception in conjunction with globlaize 3
slowjack2k opened this issue · 2 comments
slowjack2k commented
Hi,
I'm using globalize 3.1.0
with this gem I get a nil Exception within
cast_attribute
. The error starts within
def raw_sql(record)
because
record.column_for_attribute(key)
for translated columns
returns nil.
Globalize offers a method translated_attributes
to determine such attributes.
Is it possible to support globalize or simply skip columns without a database column?
Regards
Dieter
slowjack2k commented
My Work Around looks like this:
attributes = record.attributes
keys = []
values = []
attributes.each_pair do |key, value|
column = record.column_for_attribute(key)
next unless column
keys << "`#{key}`"
values << connection.quote(cast_attribute(record, column, value))
end
"INSERT INTO `#{record.class.table_name}` (#{keys.join(', ')}) VALUES (#{values.join(', ')})"
nettofarah commented
Hello, @slowjack2k!
I'm not familiar with globalize
and why it creates extra non-persistent attributes.
I think it would make sense to ignore attributes that are not columns though.
Do you wanna issue a PR?