Method: ROM::SQL::Relation::Writing#import
- Defined in:
- lib/rom/sql/relation/writing.rb
#import(other_sql_relation, options) ⇒ Integer #import(other, options) ⇒ Integer
Insert tuples from other relation
NOTE: The method implicitly uses a transaction
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/rom/sql/relation/writing.rb', line 115 def import(other, = EMPTY_HASH) columns = other.schema.map { |a| a.alias || a.name } if other.gateway.eql?(gateway) dataset.import(columns, other.dataset, ) else keys = columns.map(&:to_sym) dataset.import( columns, other.to_a.map { |record| record.to_h.values_at(*keys) }, ) end end |