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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Dec 02, 2006, at 11:13 pm, 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 > endChris, 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---