I'm trying to find an efficient way to store monthly recurring data that does not change frequently.
class Fund < ApplicationRecord
has_many :factsheets
end
class Factsheet < ApplicationRecord
belongs_to :fund
end
A Fund will have a new Factsheet per month.
Each Factsheet have an objective on it (very long text, suppose).
The objective may change each month, but not frequently (say, change once per ~10 months).
Any good way to store the objective?
Option 1:
Put objective into model Factsheet, and it will duplicate a lot.
(store 12 objectives for 12 months, but most of them may be exactly the same)
Option 2:
Make objective a model, then Fund has_many :objectives
class Objective < ApplicationRecord
belongs_to :fund
end
Objective will have a column :effective_on
to indicate: from which month a Fund should use this Objective record on its Factsheet.
(store 2 objectives for 12 months if only changed once)
Option 3:
Better idea?
I would go the simplest option in your case, which is the first one.
Now why? My motivation is scale. Option 2 is a common case of over-engineering in my view. You'll have roughly 1200 records on one table in 100 years, and let's assume for the sake of the argument that the objective never change: you'd get 1200 entries in the DB that are duplicated.
Is that a big deal? I think not. For this scale, I believe a bit of duplication is perfectly tolerable.
If you were to create an entry every second, we could argue for a better solution, but I'd advise you to go with the simplest solution and concentrate on a problem that really does need some well-engineered solutions :).