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



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

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, dec.arel_table
    rel.readonly!
    yield rel
  end
end