Module: ActiveRecord::QueryMethods
- Defined in:
- lib/postgres_with/active_record/relation/query_methods.rb
Defined Under Namespace
Classes: WithChain
Instance Method Summary collapse
- #build_arel_with_extensions(aliases = nil) ⇒ Object (also: #build_arel)
- #with(opts = :chain, *rest) ⇒ Object
-
#with!(opts = :chain, *rest) ⇒ Object
:nodoc:.
Instance Method Details
#build_arel_with_extensions(aliases = nil) ⇒ Object Also known as: build_arel
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 63 def build_arel_with_extensions(aliases = nil) arel = build_arel_without_extensions(aliases) with_statements = with_values.flat_map do |with_value| case with_value when String with_value when Hash with_value.map do |name, expression| case expression when String select = Arel::Nodes::SqlLiteral.new "(#{expression})" when ActiveRecord::Relation, Arel::SelectManager select = Arel::Nodes::SqlLiteral.new "(#{expression.to_sql})" end Arel::Nodes::As.new Arel::Nodes::SqlLiteral.new("\"#{name}\""), select end when Arel::Nodes::As with_value end end unless with_statements.empty? if recursive_value arel.with :recursive, with_statements else arel.with with_statements end end arel end |
#with(opts = :chain, *rest) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 44 def with(opts = :chain, *rest) if opts == :chain WithChain.new(spawn) elsif opts.blank? self else spawn.with!(opts, *rest) end end |
#with!(opts = :chain, *rest) ⇒ Object
:nodoc:
54 55 56 57 58 59 60 61 |
# File 'lib/postgres_with/active_record/relation/query_methods.rb', line 54 def with!(opts = :chain, *rest) # :nodoc: if opts == :chain WithChain.new(self) else self.with_values += [opts] + rest self end end |