Skip to content

Commit

Permalink
add nested set to treatments
Browse files Browse the repository at this point in the history
  • Loading branch information
kf8a committed Jun 18, 2024
1 parent 719e9d1 commit 68a6652
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion app/models/citation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 68a6652

Please sign in to comment.