3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
# File 'lib/polymorphic_as_table/association_proxy.rb', line 3
def self.included(base)
base.class_eval do
def set_belongs_to_association_for(record)
if @reflection.options[:as]
record["#{@reflection.options[:as]}_id"] = @owner.id unless @owner.new_record?
record["#{@reflection.options[:as]}_type"] = @owner.class.base_class.table_name
else
unless @owner.new_record?
primary_key = @reflection.options[:primary_key] || :id
record[@reflection.primary_key_name] = @owner.send(primary_key)
end
end
end
end
end
|