diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb index 4f5d72a..2ba3fd7 100755 --- a/activerecord/lib/active_record/base.rb +++ b/activerecord/lib/active_record/base.rb @@ -974,6 +974,11 @@ module ActiveRecord #:nodoc: end + # Specify which attributes are required (set via validates_presence_of) + attr_accessor :required_attributes + @required_attributes = [] + # Guesses the table name (in forced lower-case) based on the name of the class in the inheritance hierarchy descending # directly from ActiveRecord::Base. So if the hierarchy looks like: Reply < Message < ActiveRecord::Base, then Message is used # to guess the table name even when called on Reply. The rules used to do the guess are handled by the Inflector class diff --git a/activerecord/lib/active_record/validations.rb b/activerecord/lib/active_record/validations.rb index b957ee3..9206657 100755 --- a/activerecord/lib/active_record/validations.rb +++ b/activerecord/lib/active_record/validations.rb @@ -473,6 +473,9 @@ module ActiveRecord configuration = { :on => :save } configuration.update(attr_names.extract_options!) + # Insert the attr_names array into the calling class's required_attributes array + self.required_attributes = attr_names + # can't use validates_each here, because it cannot cope with nonexistent attributes, # while errors.add_on_empty can send(validation_method(configuration[:on]), configuration) do |record|