diff --git a/app/models/citation.rb b/app/models/citation.rb index cc058b0b..0f7e3a19 100644 --- a/app/models/citation.rb +++ b/app/models/citation.rb @@ -78,7 +78,11 @@ class Citation < ApplicationRecord end def self.by_treatment(treatment) - includes(:treatments).references(:treatments).where('treatments.id = ?', treatment) + # get the citations with the treatment and all of the child treatments + trt = Treatment.find(treatment) + child_ids = trt.children.map { |sib| sib.id } + ids = child_ids.push(trt.id) + includes(:treatments).references(:treatments).where('treatments.id in (?)', ids) end def self.by_treatments(treatment_array) diff --git a/db/migrate/20240618131120_add_awesome_nested_set_to_treatments.rb b/db/migrate/20240618131120_add_awesome_nested_set_to_treatments.rb new file mode 100644 index 00000000..ed825951 --- /dev/null +++ b/db/migrate/20240618131120_add_awesome_nested_set_to_treatments.rb @@ -0,0 +1,7 @@ +class AddAwesomeNestedSetToTreatments < ActiveRecord::Migration[7.1] + def change + add_column :treatments, :parent_id, :integer, null: true + add_column :treatments, :rgt, :integer + add_column :treatments, :lft, :integer + end +end