I have used Single Table Inheritance (STI) to create some Models with subclassed from a common parent. A separate model has an association with the superclass. Eg: as follows...
class Fruit < ActiveRecord::Base
has_many :smoothies
end
class Apple < Fruit
end
class Banana < Fruit
end
class Smoothie < ActiveRecord::Base
belongs_to :fruit
end
Is there any way to query for a certain subclass without manually creating a method for each subclass?
I would like to be able to do something along the lines of my_smoothie.apple
to get an Apple
instance if my_smoothie
is associated with an Apple
Update
My use case is actually where I have a relation of Smoothies and I want to do some_smoothies.apples
to get a relation containing any associated Apples.