Method: Simple::SQL#duplicate

Defined in:
lib/simple/sql/duplicate.rb

#duplicate(table, ids, overrides = {}) ⇒ Object

Creates duplicates of record in a table.

This method handles timestamp columns (these will be set to the current time) and primary keys (will be set to NULL.) You can pass in overrides as a third argument for specific columns.

Parameters:

  • ids: (Integer, Array<Integer>) primary key ids

  • overrides: Hash[column_names => SQL::Fragment]



24
25
26
27
28
29
# File 'lib/simple/sql/duplicate.rb', line 24

def duplicate(table, ids, overrides = {})
  ids = Array(ids)
  return [] if ids.empty?

  Duplicator.new(table, overrides).call(ids)
end