Module: ActiveRecord::Cti::SubClass

Extended by:
ActiveSupport::Concern
Defined in:
lib/activerecord/cti/sub_class.rb

Instance Method Summary collapse

Instance Method Details

#save(*args, &block) ⇒ Object

To save into two related tables while inserting.



114
115
116
117
118
119
120
121
122
123
124
125
126
# File 'lib/activerecord/cti/sub_class.rb', line 114

def save(*args, &block)
  _superclass_instance_for_rw = superclass_instance_for_rw
  _subclass_instance_for_rw = subclass_instance_for_rw
  ActiveRecord::Base.transaction do
    _superclass_instance_for_rw.send(:create_or_update)
    _subclass_instance_for_rw.send("#{foreign_key_name}=", _superclass_instance_for_rw.id)
    _subclass_instance_for_rw.send(:create_or_update)
  end
  self.id = _subclass_instance_for_rw.id
  _superclass_instance_for_rw.id.present? and _subclass_instance_for_rw.id.present?
rescue ActiveRecord::RecordInvalid
  false
end