Module: CopyMachine::ActiveRecordExtensions::Constraints

Defined in:
lib/copy_machine/active_record_extensions/constraints.rb

Instance Method Summary collapse

Instance Method Details

#disable_foreign_key_constraintsObject



11
12
13
14
15
# File 'lib/copy_machine/active_record_extensions/constraints.rb', line 11

def disable_foreign_key_constraints
  if connection.class.name == 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
    connection.execute "SET FOREIGN_KEY_CHECKS = 0"
  end
end

#enable_foreign_key_constraintsObject



17
18
19
20
21
# File 'lib/copy_machine/active_record_extensions/constraints.rb', line 17

def enable_foreign_key_constraints
  if connection.class.name == 'ActiveRecord::ConnectionAdapters::MysqlAdapter'
    connection.execute "SET FOREIGN_KEY_CHECKS = 1"
  end
end

#with_disabled_constraintsObject



5
6
7
8
9
# File 'lib/copy_machine/active_record_extensions/constraints.rb', line 5

def with_disabled_constraints
  disable_foreign_key_constraints
  yield
  enable_foreign_key_constraints
end