Reputation: 63
I have a model called Item, which belongs to Report.
class Item < ApplicationRecord
belongs_to :report
end
For my Item, I want to have an attribute called item_category(besides other attributes).
t.string "item_category"
I will have some standard categories that will have a tax associated with them.
My question is: Should I have another two models for Category and Tax, and load the available categories that will be created as options for my Item category attribute ? (or Tax should be an attribute for a Category model, or none of them)
After some time, another category can be added/removed, same for the Tax and I want this to be as modular as possible, not to make changes every time I want to remove/add category/tax. How should I approach it?
Upvotes: 0
Views: 67
Reputation: 91
I suggest the model
Upvotes: 1
Reputation: 2088
It really depends on how frequently categories will change. If tax + category pair is constant, then I would suggest adding that in code, as a constant (Hash, maybe, structured as { "category" : "tax" }). If taxes will change often, then it makes more sense of making another Category
model and storing your tax + Category stuff there.
From your description it doesn't seem like you need a separate Tax
model (I assume you will only have % amount there). This is based on an assumption that Category has only one tax.
That is all I can suggest with the information you have provided. But the most optimal methid laregly depends on more details description of your business logic
Upvotes: 1