diff --git a/app/models/concerns/has_compats.rb b/app/models/concerns/has_compats.rb deleted file mode 100644 index b222cb8..0000000 --- a/app/models/concerns/has_compats.rb +++ /dev/null @@ -1,9 +0,0 @@ -module HasCompats - # def compats - # gemmies = is_a?(Gemmy) ? self.class.where(id: self) : self.gemmies - # Compat.where(id: gemmies.from("#{Gemmy.table_name}, json_each(#{Gemmy.table_name}.compat_ids)").select("json_each.value")) - # end - def compats - Compat.where("id IN (SELECT value::bigint FROM json_array_elements_text(?))", compat_ids.to_json) - end -end diff --git a/app/models/gemmy.rb b/app/models/gemmy.rb index 2fa2f32..febec20 100644 --- a/app/models/gemmy.rb +++ b/app/models/gemmy.rb @@ -1,6 +1,4 @@ class Gemmy < ApplicationRecord - include HasCompats - FORBIDDEN_NAMES = %w( new edit @@ -11,6 +9,10 @@ class Gemmy < ApplicationRecord delegate :to_param, :to_s, to: :name + def compats + Compat.where(id: compat_ids) + end + def dependencies dependencies_and_versions .keys diff --git a/app/models/lockfile.rb b/app/models/lockfile.rb index b7ffa58..6683456 100644 --- a/app/models/lockfile.rb +++ b/app/models/lockfile.rb @@ -1,6 +1,4 @@ class Lockfile < ApplicationRecord - include HasCompats - has_many :dependencies, class_name: "LockfileDependency", dependent: :destroy has_many :gemmies, through: :dependencies @@ -11,6 +9,10 @@ class Lockfile < ApplicationRecord delegate :to_param, to: :slug scope :with_gemmies, ->(gemmies) { joins(:gemmies).where(gemmies: { id: gemmies }).distinct } + + def compats + Compat.where(id: gemmies.flat_map(&:compat_ids)) + end end # == Schema Information