I have a vast list of Lawyers, Categories, and Subcategories.
Hint (so you could have a clue if my associations are okay)
- On Categories Table, I do not want to see a column on Categories Table referencing Subcategories.
- On Subcategories Table, I do not want to see a column on Subcategories Table referencing Categories.
- Not all Categories has Subcategories. i.e. some don't have subcategories as seen in the picture.
- I have 2 separate forms creating category and subcategory.
- I added category_id and subcategory_id as foreign keys to my lawyers table. Such that I can choose from lawyers form upon create, the category or subcategory a lawyer will belong to as soon in the image.
- Also note: A Subcategory could be created at any time, any day, for Categories not having Subcategory, as well as new Subcategories under Categories already having some Subcategories, and lawyers will be placed under them.
- The image is a replica of my index/homepage I am having at the moment, at least before number 6 above takes effect any time any day, and I hope to use loop to make this view happen.
Pictorial understanding of what I am trying to do:
Here are my relationships between 3 models
class Lawyer < ActiveRecord::Base
belongs_to :category
belongs_to :subcategory
end
class Category < ActiveRecord::Base
has_many :lawyers
end
class Subcategory < ActiveRecord::Base
#belongs_to :category #Do I want "category_id" in Subcategories Table?
has_many :lawyers
end
Question
Is my association on those 3 models okay for the Hint I gave? This is pretty confusing.