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

Ensure all join table attributes will be in the same timestamp.

This commit is contained in:
José Valim 2010-07-21 14:50:04 +02:00
parent 8bb3b634c0
commit f3e42292a5

View file

@ -45,21 +45,23 @@ module ActiveRecord
if @reflection.options[:insert_sql]
@owner.connection.insert(interpolate_sql(@reflection.options[:insert_sql], record))
else
relation = Arel::Table.new(@reflection.options[:join_table])
relation = Arel::Table.new(@reflection.options[:join_table])
timestamps = record_timestamp_columns(record)
timezone = record.send(:current_time_from_proper_timezone) if timestamps.any?
attributes = columns.inject({}) do |attrs, column|
case column.name.to_s
name = column.name
case name.to_s
when @reflection.primary_key_name.to_s
attrs[relation[column.name]] = @owner.id
attrs[relation[name]] = @owner.id
when @reflection.association_foreign_key.to_s
attrs[relation[column.name]] = record.id
attrs[relation[name]] = record.id
when *timestamps
attrs[relation[name]] = timezone
else
if record.send(:all_timestamp_attributes).include?(column.name.to_sym)
if record.record_timestamps
attrs[relation[column.name]] = record.send(:current_time_from_proper_timezone)
end
elsif record.has_attribute?(column.name)
value = @owner.send(:quote_value, record[column.name], column)
attrs[relation[column.name]] = value unless value.nil?
if record.has_attribute?(name)
value = @owner.send(:quote_value, record[name], column)
attrs[relation[name]] = value unless value.nil?
end
end
attrs
@ -121,6 +123,14 @@ module ActiveRecord
build_record(attributes, &block)
end
end
def record_timestamp_columns(record)
if record.record_timestamps
record.send(:all_timestamp_attributes).map(&:to_s)
else
[]
end
end
end
end
end