Module: ActiveRecordSqlUnionizer::ClassMethods
- Defined in:
- lib/active_record_sql_unionizer/active_record_sql_unionizer.rb
Instance Method Summary collapse
-
#unionize(*queries) ⇒ ActiveRecord::Relation
passed in objects can be valid SQL strings, ActiveRecord::Relation, and class methods as symbols that return an ActiveRecord::Relation.
Instance Method Details
#unionize(*queries) ⇒ ActiveRecord::Relation
passed in objects can be valid SQL strings, ActiveRecord::Relation, and class methods as symbols that return an ActiveRecord::Relation.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/active_record_sql_unionizer/active_record_sql_unionizer.rb', line 12 def unionize(*queries) unionizer_helper = UnionizerHelper.new table_name = unionizer_helper.get_table_name(self) sql_queries = queries.map do |query| query_string = case query when String query when Symbol unionizer_helper.handle_symbol_arg(self, query) when ActiveRecord::Relation query.to_sql else raise(UnionizerError.new(type: :unknown_arg_type)) end "(#{query_string})" end union_string = unionizer_helper.construct_final_query_string(sql_queries, table_name) sql = self.connection.unprepared_statement {union_string} self.from(sql) end |