I'm trying to come up with a way of providing some kind of way in which I can do a find over a number of different models which have common fields. For example say I have two models Dog and Cat, they both have some fields the same (eg. name, age, weight) but also additional differing fields. Maybe Cat and Dog models are independant or maybe they are inhertied from the same base model, Animal. If I wanted to do a find on name, but wanted to do so for Cats and Dogs, and provide the results to the view as a single aggregated array of type Animal how would I do this?
on 2007-03-29 14:11
on 2007-03-29 14:20
Okay two things I have looked at already: STI - problem is that in the case of Cat and Dog this might work but there possibility might be Horse, Cow, Chicken, all with loads of non-common fields. Which would get pretty messy. Polymorphic Assosiations - Would this work if I had an Animal model which held the common fields and with animal_id and animal_type fields. The logic would mean when creating a new Dog, I would also need to always create a matching new Animal?