From 8c294b27c7e122ef71cfd1f865f4f207f81774a5 Mon Sep 17 00:00:00 2001 From: Alex Stupka Date: Wed, 24 Apr 2024 17:31:49 -0700 Subject: [PATCH] Fix to make active_record adapter work with 4.2 * https://github.com/flippercloud/flipper/issues/858 --- lib/flipper/adapters/active_record.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/flipper/adapters/active_record.rb b/lib/flipper/adapters/active_record.rb index cb876bf30..752a1c00f 100644 --- a/lib/flipper/adapters/active_record.rb +++ b/lib/flipper/adapters/active_record.rb @@ -130,7 +130,9 @@ def get_all rows_query = features.join(gates, ::Arel::Nodes::OuterJoin) .on(features[:key].eq(gates[:feature_key])) .project(features[:key].as('feature_key'), gates[:key], gates[:value]) - gates = @feature_class.connection.select_rows(rows_query) + select_method = rails_version_over_4_2? ? :select_rows : :select_all + gates = @feature_class.connection.send(select_method, rows_query) + # group the gates by feature key grouped_gates = gates.inject({}) do |hash, (feature_key, key, value)| @@ -149,6 +151,10 @@ def get_all end end + def rails_version_over_4_2? + Rails::VERSION::MAJOR * 10 + Rails::VERSION::MINOR > 42 + end + # Public: Enables a gate for a given thing. # # feature - The Flipper::Feature for the gate.