From dbfebd357c96f41cd168bd461c67618a9601bb5a Mon Sep 17 00:00:00 2001 From: Juzer Shakir Date: Thu, 19 Dec 2024 13:52:15 +0530 Subject: [PATCH 1/4] remove `active_record_union` dependency --- Gemfile | 1 - Gemfile.lock | 9 --------- 2 files changed, 10 deletions(-) diff --git a/Gemfile b/Gemfile index 59bcccf2..6c31dd01 100644 --- a/Gemfile +++ b/Gemfile @@ -5,7 +5,6 @@ ruby "~> 3.3.6" gem "rails", "~> 8.0.1" -gem "active_record_union", github: "brianhempel/active_record_union", branch: "master" gem "bcrypt", "~> 3.1.20" gem "bootsnap", require: false gem "cancancan", "~> 3.6.1" diff --git a/Gemfile.lock b/Gemfile.lock index 4bfd4f80..25313448 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,11 +1,3 @@ -GIT - remote: https://github.com/brianhempel/active_record_union.git - revision: 8ebe558709aabe039abd24e3e7dd4d4354a6de88 - branch: master - specs: - active_record_union (1.3.0) - activerecord (>= 6.0) - GEM remote: https://rubygems.org/ specs: @@ -401,7 +393,6 @@ PLATFORMS x86_64-linux DEPENDENCIES - active_record_union! bcrypt (~> 3.1.20) bootsnap brakeman From 77e60009aba5b715b1df656228de51b6eab26c42 Mon Sep 17 00:00:00 2001 From: Juzer Shakir Date: Thu, 19 Dec 2024 13:52:57 +0530 Subject: [PATCH 2/4] Add `union` method to `ActiveRecord::Relation` class --- app/models/concerns/active_record_relation_extensions.rb | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 app/models/concerns/active_record_relation_extensions.rb diff --git a/app/models/concerns/active_record_relation_extensions.rb b/app/models/concerns/active_record_relation_extensions.rb new file mode 100644 index 00000000..05e385e7 --- /dev/null +++ b/app/models/concerns/active_record_relation_extensions.rb @@ -0,0 +1,8 @@ +module ActiveRecordRelationExtensions + refine ActiveRecord::Relation do + def union(q) + union_query = Arel::Nodes::Union.new(arel, q.arel).as(klass.table_name) + klass.from(union_query) + end + end +end From 8116472351ba2dfaeac924f0fe24a4758ec14dd2 Mon Sep 17 00:00:00 2001 From: Juzer Shakir Date: Thu, 19 Dec 2024 13:56:24 +0530 Subject: [PATCH 3/4] Use `ActiveRecordRelationExtensions` to use `union` method --- app/models/sabeel.rb | 10 ++++++++++ app/models/thaali.rb | 1 + 2 files changed, 11 insertions(+) diff --git a/app/models/sabeel.rb b/app/models/sabeel.rb index da93c7a0..baa89e30 100644 --- a/app/models/sabeel.rb +++ b/app/models/sabeel.rb @@ -27,6 +27,7 @@ def sluggables = [its] include ITSValidation include NameValidation + using ActiveRecordRelationExtensions using ArrayExtensions # * Enums @@ -63,4 +64,13 @@ def taking_thaali? = Rails.cache.fetch("sabeel_#{id}_taking_thaali?") { thaalis. def took_thaali? = Rails.cache.fetch("sabeel_#{id}_took_thaali?") { thaalis.exists? year: PREV_YR } def last_year_thaali_dues_cleared? = thaalis.dues_cleared_in(PREV_YR).present? + + private + + # class << self + # def unioned(q1, q2) + # union_query = Arel::Nodes::Union.new(no_thaali.arel, took_thaali.arel).as("sabeels") + # from(union_query) + # end + # end end diff --git a/app/models/thaali.rb b/app/models/thaali.rb index 22c58f08..31f83d0f 100644 --- a/app/models/thaali.rb +++ b/app/models/thaali.rb @@ -23,6 +23,7 @@ class Thaali < ApplicationRecord def sluggables = [year, number] + using ActiveRecordRelationExtensions using ArrayExtensions # * Enums From 5bd2935cc990d324d867c7ef9a7eb7d55ed53bb4 Mon Sep 17 00:00:00 2001 From: Juzer Shakir Date: Thu, 19 Dec 2024 14:09:38 +0530 Subject: [PATCH 4/4] Remove dead code --- app/models/sabeel.rb | 9 --------- 1 file changed, 9 deletions(-) diff --git a/app/models/sabeel.rb b/app/models/sabeel.rb index baa89e30..64bef3cf 100644 --- a/app/models/sabeel.rb +++ b/app/models/sabeel.rb @@ -64,13 +64,4 @@ def taking_thaali? = Rails.cache.fetch("sabeel_#{id}_taking_thaali?") { thaalis. def took_thaali? = Rails.cache.fetch("sabeel_#{id}_took_thaali?") { thaalis.exists? year: PREV_YR } def last_year_thaali_dues_cleared? = thaalis.dues_cleared_in(PREV_YR).present? - - private - - # class << self - # def unioned(q1, q2) - # union_query = Arel::Nodes::Union.new(no_thaali.arel, took_thaali.arel).as("sabeels") - # from(union_query) - # end - # end end