ActiveRecord / Dissecting a has many association

From WhyNotWiki
Jump to: navigation, search
require 'unroller'
Unroller::display_style = :show_entire_method_body

class Person < ActiveRecord::Base
  Unroller::trace :exclude_classes => [Class, Module, Object, /ActiveSupport/, /Inflector/], :exclude_methods => [:assert_valid_keys, :name, /deprecat/] do
    has_many :children, :class_name => name, :foreign_key => 'parent_id', :order => 'position', :dependent => :destroy
  end
end


 |    has_many :children, :class_name => name, :foreign_key => 'parent_id', :order => 'position', :dependent => :destroy  | has_many_test.rb:8
 |  \ calling ActiveRecord::Associations::ClassMethods::has_many

ActiveRecord::Associations::ClassMethods::has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:555):
 |    (association_id = :children; options = {:dependent=>:destroy, :class_name=>"Person", :foreign_key=>"parent_id", :order=>"position"}; extension = nil; reflection = nil)
      ->       def has_many(association_id, options = {}, &extension)
                 reflection = create_has_many_reflection(association_id, options, &extension)

                 configure_dependency_for_has_many(reflection)

                 if options[:through]
                   collection_reader_method(reflection, HasManyThroughAssociation)
                 else
                   add_multiple_associated_save_callbacks(reflection.name)
                   add_association_callbacks(reflection.name, reflection.options)
                   collection_accessor_methods(reflection, HasManyAssociation)
                 end

                 add_deprecated_api_for_has_many(reflection.name)
               end


ActiveRecord::Associations::ClassMethods::has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:556):
               def has_many(association_id, options = {}, &extension)
      ->         reflection = create_has_many_reflection(association_id, options, &extension)

                 configure_dependency_for_has_many(reflection)

                 if options[:through]
                   collection_reader_method(reflection, HasManyThroughAssociation)
                 else
                   add_multiple_associated_save_callbacks(reflection.name)
                   add_association_callbacks(reflection.name, reflection.options)
                   collection_accessor_methods(reflection, HasManyAssociation)
                 end

                 add_deprecated_api_for_has_many(reflection.name)
               end

 |  |  \ calling ActiveRecord::Associations::ClassMethods::create_has_many_reflection

ActiveRecord::Associations::ClassMethods::create_has_many_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1093):
 |  |    (association_id = :children; options = {:dependent=>:destroy, :class_name=>"Person", :foreign_key=>"parent_id", :order=>"position"}; extension = nil)
         ->         def create_has_many_reflection(association_id, options, &extension)
                      options.assert_valid_keys(
                        :class_name, :table_name, :foreign_key,
                        :exclusively_dependent, :dependent,
                        :select, :conditions, :include, :order, :group, :limit, :offset,
                        :as, :through, :source, :source_type,
                        :uniq,
                        :finder_sql, :counter_sql,
                        :before_add, :after_add, :before_remove, :after_remove,
                        :extend
                      )

                      options[:extend] = create_extension_module(association_id, extension) if block_given?

                      create_reflection(:has_many, association_id, options, self)
                    end


ActiveRecord::Associations::ClassMethods::create_has_many_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1094):
                    def create_has_many_reflection(association_id, options, &extension)
         ->           options.assert_valid_keys(
                        :class_name, :table_name, :foreign_key,
                        :exclusively_dependent, :dependent,
                        :select, :conditions, :include, :order, :group, :limit, :offset,
                        :as, :through, :source, :source_type,
                        :uniq,
                        :finder_sql, :counter_sql,
                        :before_add, :after_add, :before_remove, :after_remove,
                        :extend
                      )

                      options[:extend] = create_extension_module(association_id, extension) if block_given?

                      create_reflection(:has_many, association_id, options, self)
                    end


ActiveRecord::Associations::ClassMethods::create_has_many_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1105):
                    def create_has_many_reflection(association_id, options, &extension)
                      options.assert_valid_keys(
                        :class_name, :table_name, :foreign_key,
                        :exclusively_dependent, :dependent,
                        :select, :conditions, :include, :order, :group, :limit, :offset,
                        :as, :through, :source, :source_type,
                        :uniq,
                        :finder_sql, :counter_sql,
                        :before_add, :after_add, :before_remove, :after_remove,
                        :extend
                      )

         ->           options[:extend] = create_extension_module(association_id, extension) if block_given?

                      create_reflection(:has_many, association_id, options, self)
                    end


ActiveRecord::Associations::ClassMethods::create_has_many_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1107):
                    def create_has_many_reflection(association_id, options, &extension)
                      options.assert_valid_keys(
                        :class_name, :table_name, :foreign_key,
                        :exclusively_dependent, :dependent,
                        :select, :conditions, :include, :order, :group, :limit, :offset,
                        :as, :through, :source, :source_type,
                        :uniq,
                        :finder_sql, :counter_sql,
                        :before_add, :after_add, :before_remove, :after_remove,
                        :extend
                      )

                      options[:extend] = create_extension_module(association_id, extension) if block_given?

         ->           create_reflection(:has_many, association_id, options, self)
                    end

 |  |  |  \ calling ActiveRecord::Reflection::ClassMethods::create_reflection

ActiveRecord::Reflection::ClassMethods::create_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:13):
 |  |  |    (macro = :has_many; name = :children; options = {:dependent=>:destroy, :class_name=>"Person", :foreign_key=>"parent_id", :order=>"position"}; active_record = Person; reflection = nil)
            -> def create_reflection(macro, name, options, active_record)
                 case macro
                   when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
                     reflection = AssociationReflection.new(macro, name, options, active_record)
                   when :composed_of
                     reflection = AggregateReflection.new(macro, name, options, active_record)
                 end
                 write_inheritable_hash :reflections, name => reflection
                 reflection
               end


ActiveRecord::Reflection::ClassMethods::create_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:14):
               def create_reflection(macro, name, options, active_record)
            ->   case macro
                   when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
                     reflection = AssociationReflection.new(macro, name, options, active_record)
                   when :composed_of
                     reflection = AggregateReflection.new(macro, name, options, active_record)
                 end
                 write_inheritable_hash :reflections, name => reflection
                 reflection
               end


ActiveRecord::Reflection::ClassMethods::create_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:15):
               def create_reflection(macro, name, options, active_record)
                 case macro
            ->     when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
                     reflection = AssociationReflection.new(macro, name, options, active_record)
                   when :composed_of
                     reflection = AggregateReflection.new(macro, name, options, active_record)
                 end
                 write_inheritable_hash :reflections, name => reflection
                 reflection
               end


ActiveRecord::Reflection::ClassMethods::create_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:16):
               def create_reflection(macro, name, options, active_record)
                 case macro
                   when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
            ->       reflection = AssociationReflection.new(macro, name, options, active_record)
                   when :composed_of
                     reflection = AggregateReflection.new(macro, name, options, active_record)
                 end
                 write_inheritable_hash :reflections, name => reflection
                 reflection
               end

 |  |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::initialize

ActiveRecord::Reflection::MacroReflection::initialize (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:74):
 |  |  |  |    (macro = :has_many; name = :children; options = {:dependent=>:destroy, :class_name=>"Person", :foreign_key=>"parent_id", :order=>"position"}; active_record = Person)
               -> def initialize(macro, name, options, active_record)
                    @macro, @name, @options, @active_record = macro, name, options, active_record
                  end


ActiveRecord::Reflection::MacroReflection::initialize (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:75):
                  def initialize(macro, name, options, active_record)
               ->   @macro, @name, @options, @active_record = macro, name, options, active_record
                  end

 |  |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::initialize

ActiveRecord::Reflection::ClassMethods::create_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:20):
               def create_reflection(macro, name, options, active_record)
                 case macro
                   when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
                     reflection = AssociationReflection.new(macro, name, options, active_record)
                   when :composed_of
                     reflection = AggregateReflection.new(macro, name, options, active_record)
                 end
            ->   write_inheritable_hash :reflections, name => reflection
                 reflection
               end


ActiveRecord::Reflection::ClassMethods::create_reflection (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:21):
               def create_reflection(macro, name, options, active_record)
                 case macro
                   when :has_many, :belongs_to, :has_one, :has_and_belongs_to_many
                     reflection = AssociationReflection.new(macro, name, options, active_record)
                   when :composed_of
                     reflection = AggregateReflection.new(macro, name, options, active_record)
                 end
                 write_inheritable_hash :reflections, name => reflection
            ->   reflection
               end

 |  |  |  / returning from ActiveRecord::Reflection::ClassMethods::create_reflection
 |  |  / returning from ActiveRecord::Associations::ClassMethods::create_has_many_reflection

ActiveRecord::Associations::ClassMethods::has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:558):
               def has_many(association_id, options = {}, &extension)
                 reflection = create_has_many_reflection(association_id, options, &extension)

      ->         configure_dependency_for_has_many(reflection)

                 if options[:through]
                   collection_reader_method(reflection, HasManyThroughAssociation)
                 else
                   add_multiple_associated_save_callbacks(reflection.name)
                   add_association_callbacks(reflection.name, reflection.options)
                   collection_accessor_methods(reflection, HasManyAssociation)
                 end

                 add_deprecated_api_for_has_many(reflection.name)
               end

 |  |  \ calling ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many

ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1029):
 |  |    (reflection = #<ActiveRecord::Reflection::AssociationReflection:0xb77fcee0 @macro=:has_many, @options={:dependent=>:destroy, :class_name=>"Person", :foreign_key=>"parent_id", :order=>"position"}, @active_record=Person, @name=:children>; dependent_conditions = nil)
         ->         def configure_dependency_for_has_many(reflection)
                      if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

                      if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
                      dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
                      if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

                      case reflection.options[:dependent]
                        when :destroy, true
                          module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false


ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1030):
                    def configure_dependency_for_has_many(reflection)
         ->           if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

                      if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
                      dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
                      if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

                      case reflection.options[:dependent]
                        when :destroy, true
                          module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false

 |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
            -> def options
                 @options
               end


ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:93):
               def options
            ->   @options
               end

 |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1034):
                    def configure_dependency_for_has_many(reflection)
                      if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

         ->           if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

                      if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
                      dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
                      if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

                      case reflection.options[:dependent]
                        when :destroy, true
                          module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false

 |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
            -> def options
                 @options
               end


ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:93):
               def options
            ->   @options
               end

 |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::options
 |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
            -> def options
                 @options
               end

 |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1038):
                    def configure_dependency_for_has_many(reflection)
                      if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

         ->           if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
                      dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
                      if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

                      case reflection.options[:dependent]
                        when :destroy, true
                          module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false

 |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
            -> def options
                 @options
               end


ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:93):
               def options
            ->   @options
               end

 |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1047):
                    def configure_dependency_for_has_many(reflection)
                      if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

                      if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
         ->           dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
                      if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

                      case reflection.options[:dependent]
                        when :destroy, true
                          module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false

 |  |  |  \ calling ActiveRecord::Reflection::AssociationReflection::primary_key_name

ActiveRecord::Reflection::AssociationReflection::primary_key_name (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:132):
            -> def primary_key_name
                 return @primary_key_name if @primary_key_name
                 case
                   when macro == :belongs_to
                     @primary_key_name = options[:foreign_key] || class_name.foreign_key
                   when options[:as]
                     @primary_key_name = options[:foreign_key] || "#{options[:as]}_id"
                   else
                     @primary_key_name = options[:foreign_key] || active_record.name.foreign_key
                 end
               end


ActiveRecord::Reflection::AssociationReflection::primary_key_name (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:133):
               def primary_key_name
            ->   return @primary_key_name if @primary_key_name
                 case
                   when macro == :belongs_to
                     @primary_key_name = options[:foreign_key] || class_name.foreign_key
                   when options[:as]
                     @primary_key_name = options[:foreign_key] || "#{options[:as]}_id"
                   else
                     @primary_key_name = options[:foreign_key] || active_record.name.foreign_key
                 end
               end


ActiveRecord::Reflection::AssociationReflection::primary_key_name (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:141):
               def primary_key_name
                 return @primary_key_name if @primary_key_name
                 case
                   when macro == :belongs_to
                     @primary_key_name = options[:foreign_key] || class_name.foreign_key
                   when options[:as]
                     @primary_key_name = options[:foreign_key] || "#{options[:as]}_id"
                   else
                     @primary_key_name = options[:foreign_key] || active_record.name.foreign_key
            ->   end
               end


ActiveRecord::Reflection::AssociationReflection::primary_key_name (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:135):
               def primary_key_name
                 return @primary_key_name if @primary_key_name
                 case
            ->     when macro == :belongs_to
                     @primary_key_name = options[:foreign_key] || class_name.foreign_key
                   when options[:as]
                     @primary_key_name = options[:foreign_key] || "#{options[:as]}_id"
                   else
                     @primary_key_name = options[:foreign_key] || active_record.name.foreign_key
                 end
               end

 |  |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::macro

ActiveRecord::Reflection::MacroReflection::macro (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:86):
               -> def macro
                    @macro
                  end


ActiveRecord::Reflection::MacroReflection::macro (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:87):
                  def macro
               ->   @macro
                  end

 |  |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::macro

ActiveRecord::Reflection::AssociationReflection::primary_key_name (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:137):
               def primary_key_name
                 return @primary_key_name if @primary_key_name
                 case
                   when macro == :belongs_to
                     @primary_key_name = options[:foreign_key] || class_name.foreign_key
            ->     when options[:as]
                     @primary_key_name = options[:foreign_key] || "#{options[:as]}_id"
                   else
                     @primary_key_name = options[:foreign_key] || active_record.name.foreign_key
                 end
               end

 |  |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
               -> def options
                    @options
                  end


ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:93):
                  def options
               ->   @options
                  end

 |  |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::AssociationReflection::primary_key_name (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:140):
               def primary_key_name
                 return @primary_key_name if @primary_key_name
                 case
                   when macro == :belongs_to
                     @primary_key_name = options[:foreign_key] || class_name.foreign_key
                   when options[:as]
                     @primary_key_name = options[:foreign_key] || "#{options[:as]}_id"
                   else
            ->       @primary_key_name = options[:foreign_key] || active_record.name.foreign_key
                 end
               end

 |  |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
               -> def options
                    @options
                  end


ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:93):
                  def options
               ->   @options
                  end

 |  |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::options
 |  |  |  / returning from ActiveRecord::Reflection::AssociationReflection::primary_key_name

ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1048):
                    def configure_dependency_for_has_many(reflection)
                      if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

                      if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
                      dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
         ->           if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

                      case reflection.options[:dependent]
                        when :destroy, true
                          module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false

 |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
            -> def options
                 @options
               end


ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:93):
               def options
            ->   @options
               end

 |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1052):
                    def configure_dependency_for_has_many(reflection)
                      if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

                      if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
                      dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
                      if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

         ->           case reflection.options[:dependent]
                        when :destroy, true
                          module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false

 |  |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
            -> def options
                 @options
               end


ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:93):
               def options
            ->   @options
               end

 |  |  |  / returning from ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1053):
                    def configure_dependency_for_has_many(reflection)
                      if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

                      if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
                      dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
                      if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

                      case reflection.options[:dependent]
         ->             when :destroy, true
                          module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false


ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1054):
                    def configure_dependency_for_has_many(reflection)
                      if reflection.options[:dependent] == true
                        ::ActiveSupport::Deprecation.warn("The :dependent => true option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :destroy instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      if reflection.options[:dependent] && reflection.options[:exclusively_dependent]
                        raise ArgumentError, ':dependent and :exclusively_dependent are mutually exclusive options.  You may specify one or the other.'
                      end

                      if reflection.options[:exclusively_dependent]
                        reflection.options[:dependent] = :delete_all
                        ::ActiveSupport::Deprecation.warn("The :exclusively_dependent option is deprecated and will be removed from Rails 2.0.  Please use :dependent => :delete_all instead.  See http://www.rubyonrails.org/deprecation for details.", caller)
                      end

                      # See HasManyAssociation#delete_records.  Dependent associations
                      # delete children, otherwise foreign key is set to NULL.

                      # Add polymorphic type if the :as option is present
                      dependent_conditions = %(#{reflection.primary_key_name} = \#{record.quoted_id})
                      if reflection.options[:as]
                        dependent_conditions += " AND #{reflection.options[:as]}_type = '#{base_class.name}'"
                      end

                      case reflection.options[:dependent]
                        when :destroy, true
         ->               module_eval "before_destroy '#{reflection.name}.each { |o| o.destroy }'", __FILE__, __LINE__
                        when :delete_all
                          module_eval "before_destroy { |record| #{reflection.class_name}.delete_all(%(#{dependent_conditions})) }", __FILE__, __LINE__
                        when :nullify
                          module_eval "before_destroy { |record| #{reflection.class_name}.update_all(%(#{reflection.primary_key_name} = NULL),  %(#{dependent_conditions})) }", __FILE__, __LINE__
                        when nil, false

 |  |  |  \ calling ActiveRecord::Base::before_destroy

ActiveRecord::Base::before_destroy ((eval):1):
 |  |  |    (callbacks = ["children.each { |o| o.destroy }"]; block = nil)
nil


ActiveRecord::Base::before_destroy ((eval):2):
nil


ActiveRecord::Base::before_destroy ((eval):3):
nil

 |  |  |  / returning from ActiveRecord::Base::before_destroy
 |  |  / returning from ActiveRecord::Associations::ClassMethods::configure_dependency_for_has_many

ActiveRecord::Associations::ClassMethods::has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:560):
               def has_many(association_id, options = {}, &extension)
                 reflection = create_has_many_reflection(association_id, options, &extension)

                 configure_dependency_for_has_many(reflection)

      ->         if options[:through]
                   collection_reader_method(reflection, HasManyThroughAssociation)
                 else
                   add_multiple_associated_save_callbacks(reflection.name)
                   add_association_callbacks(reflection.name, reflection.options)
                   collection_accessor_methods(reflection, HasManyAssociation)
                 end

                 add_deprecated_api_for_has_many(reflection.name)
               end


ActiveRecord::Associations::ClassMethods::has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:563):
               def has_many(association_id, options = {}, &extension)
                 reflection = create_has_many_reflection(association_id, options, &extension)

                 configure_dependency_for_has_many(reflection)

                 if options[:through]
                   collection_reader_method(reflection, HasManyThroughAssociation)
                 else
      ->           add_multiple_associated_save_callbacks(reflection.name)
                   add_association_callbacks(reflection.name, reflection.options)
                   collection_accessor_methods(reflection, HasManyAssociation)
                 end

                 add_deprecated_api_for_has_many(reflection.name)
               end

 |  |  \ calling ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks

ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:964):
 |  |    (association_name = :children; method_name = nil; after_callback = nil)
         ->         def add_multiple_associated_save_callbacks(association_name)
                      method_name = "validate_associated_records_for_#{association_name}".to_sym
                      define_method(method_name) do
                        association = instance_variable_get("@#{association_name}")
                        if association.respond_to?(:loaded?)
                          if new_record?
                            association
                          else
                            association.select { |record| record.new_record? }
                          end.each do |record|
                            errors.add "#{association_name}" unless record.valid?
                          end
                        end
                      end

                      validate method_name
                      before_save("@new_record_before_save = new_record?; true")

                      after_callback = <<-end_eval
                        association = instance_variable_get("@#{association_name}")

                        if association.respond_to?(:loaded?)
                          if @new_record_before_save
                            records_to_save = association
                          else
                            records_to_save = association.select { |record| record.new_record? }
                          end
                          records_to_save.each { |record| association.send(:insert_record, record) }
                          association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
                        end
                      end_eval


ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:965):
                    def add_multiple_associated_save_callbacks(association_name)
         ->           method_name = "validate_associated_records_for_#{association_name}".to_sym
                      define_method(method_name) do
                        association = instance_variable_get("@#{association_name}")
                        if association.respond_to?(:loaded?)
                          if new_record?
                            association
                          else
                            association.select { |record| record.new_record? }
                          end.each do |record|
                            errors.add "#{association_name}" unless record.valid?
                          end
                        end
                      end

                      validate method_name
                      before_save("@new_record_before_save = new_record?; true")

                      after_callback = <<-end_eval
                        association = instance_variable_get("@#{association_name}")

                        if association.respond_to?(:loaded?)
                          if @new_record_before_save
                            records_to_save = association
                          else
                            records_to_save = association.select { |record| record.new_record? }
                          end
                          records_to_save.each { |record| association.send(:insert_record, record) }
                          association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
                        end
                      end_eval


ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:966):
                    def add_multiple_associated_save_callbacks(association_name)
                      method_name = "validate_associated_records_for_#{association_name}".to_sym
         ->           define_method(method_name) do
                        association = instance_variable_get("@#{association_name}")
                        if association.respond_to?(:loaded?)
                          if new_record?
                            association
                          else
                            association.select { |record| record.new_record? }
                          end.each do |record|
                            errors.add "#{association_name}" unless record.valid?
                          end
                        end
                      end

                      validate method_name
                      before_save("@new_record_before_save = new_record?; true")

                      after_callback = <<-end_eval
                        association = instance_variable_get("@#{association_name}")

                        if association.respond_to?(:loaded?)
                          if @new_record_before_save
                            records_to_save = association
                          else
                            records_to_save = association.select { |record| record.new_record? }
                          end
                          records_to_save.each { |record| association.send(:insert_record, record) }
                          association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
                        end
                      end_eval


ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:979):
                    def add_multiple_associated_save_callbacks(association_name)
                      method_name = "validate_associated_records_for_#{association_name}".to_sym
                      define_method(method_name) do
                        association = instance_variable_get("@#{association_name}")
                        if association.respond_to?(:loaded?)
                          if new_record?
                            association
                          else
                            association.select { |record| record.new_record? }
                          end.each do |record|
                            errors.add "#{association_name}" unless record.valid?
                          end
                        end
                      end

         ->           validate method_name
                      before_save("@new_record_before_save = new_record?; true")

                      after_callback = <<-end_eval
                        association = instance_variable_get("@#{association_name}")

                        if association.respond_to?(:loaded?)
                          if @new_record_before_save
                            records_to_save = association
                          else
                            records_to_save = association.select { |record| record.new_record? }
                          end
                          records_to_save.each { |record| association.send(:insert_record, record) }
                          association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
                        end
                      end_eval

 |  |  |  \ calling ActiveRecord::Validations::ClassMethods::validate

ActiveRecord::Validations::ClassMethods::validate (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:239):
 |  |  |    (methods = [:validate_associated_records_for_children]; block = nil)
            -> def validate(*methods, &block)
                 methods << block if block_given?
                 write_inheritable_set(:validate, methods)
               end


ActiveRecord::Validations::ClassMethods::validate (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:240):
               def validate(*methods, &block)
            ->   methods << block if block_given?
                 write_inheritable_set(:validate, methods)
               end


ActiveRecord::Validations::ClassMethods::validate (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:241):
               def validate(*methods, &block)
                 methods << block if block_given?
            ->   write_inheritable_set(:validate, methods)
               end

 |  |  |  |  \ calling ActiveRecord::Validations::ClassMethods::write_inheritable_set

ActiveRecord::Validations::ClassMethods::write_inheritable_set (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:734):
 |  |  |  |    (key = :validate; methods = [:validate_associated_records_for_children]; existing_methods = nil)
               -> def write_inheritable_set(key, methods)
                    existing_methods = read_inheritable_attribute(key) || []
                    write_inheritable_attribute(key, methods | existing_methods)
                  end


ActiveRecord::Validations::ClassMethods::write_inheritable_set (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:735):
                  def write_inheritable_set(key, methods)
               ->   existing_methods = read_inheritable_attribute(key) || []
                    write_inheritable_attribute(key, methods | existing_methods)
                  end


ActiveRecord::Validations::ClassMethods::write_inheritable_set (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/validations.rb:736):
                  def write_inheritable_set(key, methods)
                    existing_methods = read_inheritable_attribute(key) || []
               ->   write_inheritable_attribute(key, methods | existing_methods)
                  end

 |  |  |  |  / returning from ActiveRecord::Validations::ClassMethods::write_inheritable_set
 |  |  |  / returning from ActiveRecord::Validations::ClassMethods::validate

ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:980):
                    def add_multiple_associated_save_callbacks(association_name)
                      method_name = "validate_associated_records_for_#{association_name}".to_sym
                      define_method(method_name) do
                        association = instance_variable_get("@#{association_name}")
                        if association.respond_to?(:loaded?)
                          if new_record?
                            association
                          else
                            association.select { |record| record.new_record? }
                          end.each do |record|
                            errors.add "#{association_name}" unless record.valid?
                          end
                        end
                      end

                      validate method_name
         ->           before_save("@new_record_before_save = new_record?; true")

                      after_callback = <<-end_eval
                        association = instance_variable_get("@#{association_name}")

                        if association.respond_to?(:loaded?)
                          if @new_record_before_save
                            records_to_save = association
                          else
                            records_to_save = association.select { |record| record.new_record? }
                          end
                          records_to_save.each { |record| association.send(:insert_record, record) }
                          association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
                        end
                      end_eval

 |  |  |  \ calling ActiveRecord::Base::before_save

ActiveRecord::Base::before_save ((eval):1):
 |  |  |    (callbacks = ["@new_record_before_save = new_record?; true"]; block = nil)
nil


ActiveRecord::Base::before_save ((eval):2):
nil


ActiveRecord::Base::before_save ((eval):3):
nil

 |  |  |  / returning from ActiveRecord::Base::before_save

ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:982):
                    def add_multiple_associated_save_callbacks(association_name)
                      method_name = "validate_associated_records_for_#{association_name}".to_sym
                      define_method(method_name) do
                        association = instance_variable_get("@#{association_name}")
                        if association.respond_to?(:loaded?)
                          if new_record?
                            association
                          else
                            association.select { |record| record.new_record? }
                          end.each do |record|
                            errors.add "#{association_name}" unless record.valid?
                          end
                        end
                      end

                      validate method_name
                      before_save("@new_record_before_save = new_record?; true")

         ->           after_callback = <<-end_eval
                        association = instance_variable_get("@#{association_name}")

                        if association.respond_to?(:loaded?)
                          if @new_record_before_save
                            records_to_save = association
                          else
                            records_to_save = association.select { |record| record.new_record? }
                          end
                          records_to_save.each { |record| association.send(:insert_record, record) }
                          association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
                        end
                      end_eval


ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:997):
                    def add_multiple_associated_save_callbacks(association_name)
                      method_name = "validate_associated_records_for_#{association_name}".to_sym
                      define_method(method_name) do
                        association = instance_variable_get("@#{association_name}")
                        if association.respond_to?(:loaded?)
                          if new_record?
                            association
                          else
                            association.select { |record| record.new_record? }
                          end.each do |record|
                            errors.add "#{association_name}" unless record.valid?
                          end
                        end
                      end

                      validate method_name
                      before_save("@new_record_before_save = new_record?; true")

                      after_callback = <<-end_eval
                        association = instance_variable_get("@#{association_name}")

                        if association.respond_to?(:loaded?)
                          if @new_record_before_save
                            records_to_save = association
                          else
                            records_to_save = association.select { |record| record.new_record? }
                          end
                          records_to_save.each { |record| association.send(:insert_record, record) }
                          association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
                        end
                      end_eval

 |  |  |  \ calling ActiveRecord::Base::after_create

ActiveRecord::Base::after_create ((eval):1):
 |  |  |    (callbacks = ["            association = instance_variable_get(\"@children\")\n            \n            if association.respond_to?(:loaded?)\n              if @new_record_before_save\n                records_to_save = association\n              else\n                records_to_save = association.select { |record| record.new_record? }\n              end\n              records_to_save.each { |record| association.send(:insert_record, record) }\n              association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id\n            end\n"]; block = nil)
nil


ActiveRecord::Base::after_create ((eval):2):
nil


ActiveRecord::Base::after_create ((eval):3):
nil

 |  |  |  / returning from ActiveRecord::Base::after_create

ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:998):
                    def add_multiple_associated_save_callbacks(association_name)
                      method_name = "validate_associated_records_for_#{association_name}".to_sym
                      define_method(method_name) do
                        association = instance_variable_get("@#{association_name}")
                        if association.respond_to?(:loaded?)
                          if new_record?
                            association
                          else
                            association.select { |record| record.new_record? }
                          end.each do |record|
                            errors.add "#{association_name}" unless record.valid?
                          end
                        end
                      end

                      validate method_name
                      before_save("@new_record_before_save = new_record?; true")

                      after_callback = <<-end_eval
                        association = instance_variable_get("@#{association_name}")

                        if association.respond_to?(:loaded?)
                          if @new_record_before_save
                            records_to_save = association
                          else
                            records_to_save = association.select { |record| record.new_record? }
                          end
                          records_to_save.each { |record| association.send(:insert_record, record) }
                          association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id
                        end
                      end_eval

 |  |  |  \ calling ActiveRecord::Base::after_update

ActiveRecord::Base::after_update ((eval):1):
 |  |  |    (callbacks = ["            association = instance_variable_get(\"@children\")\n            \n            if association.respond_to?(:loaded?)\n              if @new_record_before_save\n                records_to_save = association\n              else\n                records_to_save = association.select { |record| record.new_record? }\n              end\n              records_to_save.each { |record| association.send(:insert_record, record) }\n              association.send(:construct_sql)   # reconstruct the SQL queries now that we know the owner's id\n            end\n"]; block = nil)
nil


ActiveRecord::Base::after_update ((eval):2):
nil


ActiveRecord::Base::after_update ((eval):3):
nil

 |  |  |  / returning from ActiveRecord::Base::after_update
 |  |  / returning from ActiveRecord::Associations::ClassMethods::add_multiple_associated_save_callbacks

ActiveRecord::Associations::ClassMethods::has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:564):
               def has_many(association_id, options = {}, &extension)
                 reflection = create_has_many_reflection(association_id, options, &extension)

                 configure_dependency_for_has_many(reflection)

                 if options[:through]
                   collection_reader_method(reflection, HasManyThroughAssociation)
                 else
                   add_multiple_associated_save_callbacks(reflection.name)
      ->           add_association_callbacks(reflection.name, reflection.options)
                   collection_accessor_methods(reflection, HasManyAssociation)
                 end

                 add_deprecated_api_for_has_many(reflection.name)
               end

 |  |  \ calling ActiveRecord::Reflection::MacroReflection::options

ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:92):
         -> def options
              @options
            end


ActiveRecord::Reflection::MacroReflection::options (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/reflection.rb:93):
            def options
         ->   @options
            end

 |  |  / returning from ActiveRecord::Reflection::MacroReflection::options
 |  |  \ calling ActiveRecord::Associations::ClassMethods::add_association_callbacks

ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1267):
 |  |    (association_name = :children; options = {:dependent=>:destroy, :class_name=>"Person", :foreign_key=>"parent_id", :order=>"position"}; callbacks = nil)
         -> def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1268):
            def add_association_callbacks(association_name, options)
         ->   callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1269):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
         ->   callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1270):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
         ->     full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1271):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
         ->     defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1272):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
         ->     if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1270):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
         ->     full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1271):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
         ->     defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1272):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
         ->     if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1270):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
         ->     full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1271):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
         ->     defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1272):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
         ->     if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1270):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
         ->     full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1271):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
         ->     defined_callbacks = options[callback_name.to_sym]
                if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end


ActiveRecord::Associations::ClassMethods::add_association_callbacks (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:1272):
            def add_association_callbacks(association_name, options)
              callbacks = %w(before_add after_add before_remove after_remove)
              callbacks.each do |callback_name|
                full_callback_name = "#{callback_name}_for_#{association_name}"
                defined_callbacks = options[callback_name.to_sym]
         ->     if options.has_key?(callback_name.to_sym)
                  class_inheritable_reader full_callback_name.to_sym
                  write_inheritable_array(full_callback_name.to_sym, [defined_callbacks].flatten)
                end
              end
            end

 |  |  / returning from ActiveRecord::Associations::ClassMethods::add_association_callbacks

ActiveRecord::Associations::ClassMethods::has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:565):
               def has_many(association_id, options = {}, &extension)
                 reflection = create_has_many_reflection(association_id, options, &extension)

                 configure_dependency_for_has_many(reflection)

                 if options[:through]
                   collection_reader_method(reflection, HasManyThroughAssociation)
                 else
                   add_multiple_associated_save_callbacks(reflection.name)
                   add_association_callbacks(reflection.name, reflection.options)
      ->           collection_accessor_methods(reflection, HasManyAssociation)
                 end

                 add_deprecated_api_for_has_many(reflection.name)
               end

 |  |  \ calling ActiveRecord::Associations::ClassMethods::collection_accessor_methods

ActiveRecord::Associations::ClassMethods::collection_accessor_methods (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:944):
 |  |    (reflection = #<ActiveRecord::Reflection::AssociationReflection:0xb77fcee0 @primary_key_name="parent_id", @macro=:has_many, @options={:dependent=>:destroy, :class_name=>"Person", :foreign_key=>"parent_id", :order=>"position"}, @active_record=Person, @name=:children>; association_proxy_class = ActiveRecord::Associations::HasManyAssociation)
         ->         def collection_accessor_methods(reflection, association_proxy_class)
                      collection_reader_method(reflection, association_proxy_class)

                      define_method("#{reflection.name}=") do |new_value|
                        # Loads proxy class instance (defined in collection_reader_method) if not already loaded
                        association = send(reflection.name)
                        association.replace(new_value)
                        association
                      end

                      define_method("#{reflection.name.to_s.singularize}_ids") do
                        send(reflection.name).map(&:id)
                      end

                      define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
                        ids = (new_value || []).reject { |nid| nid.blank? }
                        send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
                      end
                    end


ActiveRecord::Associations::ClassMethods::collection_accessor_methods (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:945):
                    def collection_accessor_methods(reflection, association_proxy_class)
         ->           collection_reader_method(reflection, association_proxy_class)

                      define_method("#{reflection.name}=") do |new_value|
                        # Loads proxy class instance (defined in collection_reader_method) if not already loaded
                        association = send(reflection.name)
                        association.replace(new_value)
                        association
                      end

                      define_method("#{reflection.name.to_s.singularize}_ids") do
                        send(reflection.name).map(&:id)
                      end

                      define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
                        ids = (new_value || []).reject { |nid| nid.blank? }
                        send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
                      end
                    end

 |  |  |  \ calling ActiveRecord::Associations::ClassMethods::collection_reader_method

ActiveRecord::Associations::ClassMethods::collection_reader_method (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:928):
 |  |  |    (reflection = #<ActiveRecord::Reflection::AssociationReflection:0xb77fcee0 @primary_key_name="parent_id", @macro=:has_many, @options={:dependent=>:destroy, :class_name=>"Person", :foreign_key=>"parent_id", :order=>"position"}, @active_record=Person, @name=:children>; association_proxy_class = ActiveRecord::Associations::HasManyAssociation)
            ->         def collection_reader_method(reflection, association_proxy_class)
                         define_method(reflection.name) do |*params|
                           force_reload = params.first unless params.empty?
                           association = instance_variable_get("@#{reflection.name}")

                           unless association.respond_to?(:loaded?)
                             association = association_proxy_class.new(self, reflection)
                             instance_variable_set("@#{reflection.name}", association)
                           end

                           association.reload if force_reload

                           association
                         end
                       end


ActiveRecord::Associations::ClassMethods::collection_reader_method (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:929):
                       def collection_reader_method(reflection, association_proxy_class)
            ->           define_method(reflection.name) do |*params|
                           force_reload = params.first unless params.empty?
                           association = instance_variable_get("@#{reflection.name}")

                           unless association.respond_to?(:loaded?)
                             association = association_proxy_class.new(self, reflection)
                             instance_variable_set("@#{reflection.name}", association)
                           end

                           association.reload if force_reload

                           association
                         end
                       end

 |  |  |  / returning from ActiveRecord::Associations::ClassMethods::collection_reader_method

ActiveRecord::Associations::ClassMethods::collection_accessor_methods (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:947):
                    def collection_accessor_methods(reflection, association_proxy_class)
                      collection_reader_method(reflection, association_proxy_class)

         ->           define_method("#{reflection.name}=") do |new_value|
                        # Loads proxy class instance (defined in collection_reader_method) if not already loaded
                        association = send(reflection.name)
                        association.replace(new_value)
                        association
                      end

                      define_method("#{reflection.name.to_s.singularize}_ids") do
                        send(reflection.name).map(&:id)
                      end

                      define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
                        ids = (new_value || []).reject { |nid| nid.blank? }
                        send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
                      end
                    end


ActiveRecord::Associations::ClassMethods::collection_accessor_methods (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:954):
                    def collection_accessor_methods(reflection, association_proxy_class)
                      collection_reader_method(reflection, association_proxy_class)

                      define_method("#{reflection.name}=") do |new_value|
                        # Loads proxy class instance (defined in collection_reader_method) if not already loaded
                        association = send(reflection.name)
                        association.replace(new_value)
                        association
                      end

         ->           define_method("#{reflection.name.to_s.singularize}_ids") do
                        send(reflection.name).map(&:id)
                      end

                      define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
                        ids = (new_value || []).reject { |nid| nid.blank? }
                        send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
                      end
                    end


ActiveRecord::Associations::ClassMethods::collection_accessor_methods (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:958):
                    def collection_accessor_methods(reflection, association_proxy_class)
                      collection_reader_method(reflection, association_proxy_class)

                      define_method("#{reflection.name}=") do |new_value|
                        # Loads proxy class instance (defined in collection_reader_method) if not already loaded
                        association = send(reflection.name)
                        association.replace(new_value)
                        association
                      end

                      define_method("#{reflection.name.to_s.singularize}_ids") do
                        send(reflection.name).map(&:id)
                      end

         ->           define_method("#{reflection.name.to_s.singularize}_ids=") do |new_value|
                        ids = (new_value || []).reject { |nid| nid.blank? }
                        send("#{reflection.name}=", reflection.class_name.constantize.find(ids))
                      end
                    end

 |  |  / returning from ActiveRecord::Associations::ClassMethods::collection_accessor_methods

ActiveRecord::Associations::ClassMethods::has_many (/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/associations.rb:568):
               def has_many(association_id, options = {}, &extension)
                 reflection = create_has_many_reflection(association_id, options, &extension)

                 configure_dependency_for_has_many(reflection)

                 if options[:through]
                   collection_reader_method(reflection, HasManyThroughAssociation)
                 else
                   add_multiple_associated_save_callbacks(reflection.name)
                   add_association_callbacks(reflection.name, reflection.options)
                   collection_accessor_methods(reflection, HasManyAssociation)
                 end

      ->         add_deprecated_api_for_has_many(reflection.name)
               end

 |  / returning from ActiveRecord::Associations::ClassMethods::has_many
 

(To compare this trace with the one I had before, check out ActiveRecord / Dissecting a has many association / 1 - Manual dissection before I had automatic)

Ads
Personal tools