I have the following models:
Technician
- id
- name
- personal_id
Tool
- id
- internal_code
- name
- category
A technician can have many tools and one tool can be assigned to many technician (do I really need many-to-many relationship, as I’m typing this I have my doubts). My problem is that I also need to track the quantity of the tool that the technician have under his possession. One record should be like [technician_id, tool_id, quantity]. I have read about the has_many through, but i have not seen an example that fit my problem, what should the structure of the resulting table and also how should I set up the model for tools under the technician possession?
It seems like you are looking for a many-to-many association here.
This should work for you given the requirements you set:
Hope it helps.
UPDATE
Thinking about your comment about having a quantity field in
Assignments, I’m assuming you are wanting to be able to assign many of the sameToolto aTechnician. For example:If this is not the case, let me know & I can update with another approach.