Module: ActiveRecordPgStuff::Relation::TemporaryTable

Defined in:
lib/activerecord_pg_stuff/relation/temporary_table.rb

Defined Under Namespace

Classes: Decorator

Instance Method Summary collapse

Instance Method Details

#temporary_tableObject



27
28
29
30
31
32
33
34
35
# File 'lib/activerecord_pg_stuff/relation/temporary_table.rb', line 27

def temporary_table
  tname = "temporary_#{self.table.name}_#{self.object_id}"
  self.klass.connection.with_temporary_table tname, self.to_sql do |name|
    dec     = Decorator.new self.klass, name
    rel     = ActiveRecord::Relation.new dec, table: dec.arel_table
    rel.readonly!
    yield rel
  end
end