Lets say I have 3 Models called Dog, Cat and Mouse. I want all three to be able to have the same, different and many categories. I also want to add logic to a category and create it regularly like the other models. So it could be like:
Dog.categories = brown, spots, heavy fur, weak limbs
Cat.categories = brown, red, heavy fur
Mouse.categories = brown, small
Category
has_and_belongs_to_many :dogs
has_and_belongs_to_many :cats
has_and_belongs_to_many :mouses
def watch_health
if self.name == "weak limbs"
do stuff here
end
end
Now with that said. How would the model and table design be. I don’t fully understand how a polymorphic association would work in this setting so it seems like a HATBM for all 3 would be the correct way to go. What do you think? Is this correct?
Ok so I ended up doing a
has_many :throughassociation and you can get more help from here and here.