Class: ActiveRecord::Associations::HasOneAssociation

Inherits:
Object
  • Object
show all
Defined in:
lib/classy-inheritance.rb

Instance Method Summary collapse

Instance Method Details

#set_belongs_to_association_for(record) ⇒ Object

this is fixed in 2.3, but it doesn’t hurt to leave it here



44
45
46
47
48
49
50
51
52
53
54
# File 'lib/classy-inheritance.rb', line 44

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.name.to_s
  else
    unless @owner.new_record?
      primary_key = @reflection.options[:primary_key] || :id
      record[@reflection.primary_key_name] = @owner.send(primary_key)
    end
  end
end