1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/activerecord/test/models/ship.rb
Sean Griffin 56a3d5ec91 Don't redefine autosave association callbacks in nested attrs
These callbacks will already have been defined when the association was
built. The check against `reflection.autosave` happens at call time, not
at define time, so simply modifying the reflection is sufficient.

Fixes #18704
2015-01-28 09:53:38 -07:00

26 lines
805 B
Ruby

class Ship < ActiveRecord::Base
self.record_timestamps = false
belongs_to :pirate
belongs_to :update_only_pirate, :class_name => 'Pirate'
has_many :parts, :class_name => 'ShipPart'
has_many :treasures
accepts_nested_attributes_for :parts, :allow_destroy => true
accepts_nested_attributes_for :pirate, :allow_destroy => true, :reject_if => proc(&:empty?)
accepts_nested_attributes_for :update_only_pirate, :update_only => true
validates_presence_of :name
attr_accessor :cancel_save_from_callback
before_save :cancel_save_callback_method, :if => :cancel_save_from_callback
def cancel_save_callback_method
throw(:abort)
end
end
class FamousShip < ActiveRecord::Base
self.table_name = 'ships'
belongs_to :famous_pirate
validates_presence_of :name, on: :conference
end