From 14809b35af261050ccd9e03ff16f2b394336ac31 Mon Sep 17 00:00:00 2001 From: simon lehericey Date: Wed, 9 Oct 2024 09:21:44 +0200 Subject: [PATCH] add comments --- app/models/column.rb | 5 +++++ app/models/concerns/columns_concern.rb | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/app/models/column.rb b/app/models/column.rb index a62b129f1..662bfda76 100644 --- a/app/models/column.rb +++ b/app/models/column.rb @@ -18,8 +18,13 @@ class Column @displayable = displayable end + # the id is a String to be used in forms def id = h_id.to_json + + # the h_id is a Hash and hold enough information to find the column + # in the ColumnType class, aka be able to do the h_id -> column conversion def h_id = { procedure_id: @procedure_id, column_id: "#{table}/#{column}" } + def ==(other) = h_id == other.h_id # using h_id instead of id to avoid inversion of keys def to_json diff --git a/app/models/concerns/columns_concern.rb b/app/models/concerns/columns_concern.rb index 102df0b7a..a3c62fe50 100644 --- a/app/models/concerns/columns_concern.rb +++ b/app/models/concerns/columns_concern.rb @@ -4,6 +4,10 @@ module ColumnsConcern extend ActiveSupport::Concern included do + # we cannot use column.id ( == { procedure_id, column_id }.to_json) + # as the order of the keys is not guaranteed + # instead, we are using h_id == { procedure_id:, column_id: } + # another way to find a column is to look for its label def find_column(h_id: nil, label: nil) return columns.find { _1.h_id == h_id } if h_id.present? return columns.find { _1.label == label } if label.present?