module ActiveRecord::Singleton
Private Instance Methods
create_or_update()
click to toggle source
# File lib/active_record/singleton.rb, line 15 def create_or_update run_callbacks(:save) do raise ReadOnlyRecord if readonly? # Singleton record singleton = self.class.first # Force overriding the one-and-only singleton record (if any) self.id = singleton.id if singleton # Update if a singleton record is found, otherwise insert one result = singleton ? update_record : create_record result != false end end