Strict STI?

Is there a way to set the base class to abstract? or otherwise enforce
that no one can create a "Pet"?

Pet < ActiveRecord
Dog < Pet
Pig < Pet

I've tried:

class Pet < ActiveRecord::Base
  validates_presence_of :type
end

but I get an error about
../vendor/rails/activerecord/lib/active_record/validations.rb:74:
warning: Object#type is deprecated; use Object#class

Chris.Mohr wrote:

Is there a way to set the base class to abstract? or otherwise enforce
that no one can create a "Pet"?

Pet < ActiveRecord
Dog < Pet
Pig < Pet

I've tried:

class Pet < ActiveRecord::Base
  validates_presence_of :type
end

but I get an error about
../vendor/rails/activerecord/lib/active_record/validations.rb:74:
warning: Object#type is deprecated; use Object#class

>

There may be other (better) ways but the way I've done it is:

  def validate
      errors.add_to_base "You can not have an item of the base class,
Pet" unless self.class != Pet
  end

CT

Chris,

Try this (untested and completely hypothetical):

class Pet < ActiveRecord::Base
   elf.abstract_class = true
end

Off the top of my head, I don't know what happens if you try and instantiate one of these though.

Ashley