Topic: Inheritence between Active Record models
Using the classic Dog < Animal, if both of these objects are persisted in the database, how do you wire them up together? For example,
class Animal < ActiveRecord::Base
attr_accessible :sound
end
class Dog < Animal
attr_accessible :license
endSo if I want to get an instance of Dog, I would do "dog = Dog.find(1)", which should contain dog#license=123 and dog#sound="woof". The question I'm having is how does rails / ActiveRecord wire together the correct instances of animal and dog? Does there need to be a belongs_to in dog? Which means I would need an animal_id in dog, which feels more like a "has a" instead of an "is a" relationship.
Last edited by jcblitz (2012-10-31 13:59:57)