So I have a data model that is a bit complex, and am trying to figure out how to model it.
I have Client
. That Client
belongs_to a Firm
.
The Firm
will have attributes like:
- Firm Size (0.2, 0.4, 0.6, etc.)
- Firm Type (Big, Small, Medium)
- Priority Level (1, 2, 3, 4, 5 - from low to high)
A User
has_many Clients
.
That user needs to be able to edit the attributes of each firm:
E.g. add a new size to Firm Size
(say 0.95).
So I was thinking of having a Firm
model. Then also having a model for each of the attributes individually. So that way a user can add a new record to Firm Size, etc.
What I am a little confused about is the naming, and wouldn't that make the entry for each Firm
look a bit weird, given foreign_ids and all? and how would I manipulate the data?
E.g. For a Firm, the record might look like this:
:name => "Firm A", :firm_size_id => 1, :firm_type_id => 2, :priority_level_id => 1
Then, when I want to find the size of a firm, I have to run a query like this:
Firm.find(1).firm_size.size
For FirmSize, what would I name the attribute: 'size'? If I do that, then I would do a Rails call like above of like this?:
FirmSize.find(1).size
That looks a little awkward. Or would I name the attribute name
? FirmSize.find(1).name
- but that doesn't fully capture what it is. It is the size of the firm, in this case.
The same applies to 'FirmType' and 'PriorityLevel', etc.
Then the other concern is once I want to do any calculations on these attributes, won't I have to do some weird gymnastics, like:
product = Firm.find(1).firmsize.size * Firm.find(2).firmsize.size
That seems a bit awkward...or is this normal?
Would love any help with clarifying the way I approach this.
Thanks!