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
#activerecord52? ⇒ Boolean
41 42 43 |
# File 'lib/activerecord_pg_stuff/relation/temporary_table.rb', line 41 def activerecord52? ActiveRecord.gem_version >= Gem::Version.new("5.2.x") end |
#temporary_table ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 |
# 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 if activerecord52? rel = ActiveRecord::Relation.new dec else rel = ActiveRecord::Relation.new dec, dec.arel_table, dec.predicate_builder, {} end rel.readonly! yield rel end end |