HasAndBelongsToMany rails类构建方法调用super

时间:2012-05-02 22:53:27

标签: ruby-on-rails ruby ruby-on-rails-3

我试图追逐我认为是Rails中has_and_belongs_to_many方法中的错误。问题是我正在为我的班级使用不规则的复数。我们将此类称为StreetOfCars。我正确设置了不规则的复数,如下所述。类名只是示例,重要的是StreetOfCars的不规则性以及以's'结尾。我有两个问题。

  1. 到底发生了什么事?
  2. 超级终于在哪里降落?
  3. 如果您需要任何其他信息,请与我们联系。

    StreetOfCars.reflect_on_assocation(:cities).options[:join_table]
    #=> 'cities_streets_of_cars'
    
    City.reflect_on_assocation(:streets_of_cars).options[:join_table]
    #=> 'cities_streets_of_car'
    
    class StreetOfGold
      has_and_belongs_to_many :cities
    end
    
    class City
     has_and_belongs_to_many :streets_of_gold
    end
    
    #File config/initializers/inflections.rb
       ActiveSupport::Inflector.inflections do |inflect|
         inflect.irregular 'street_of_gold', 'streets_of_gold'
       end
    
    # File activerecord/lib/active_record/associations/builder/has_and_belongs_to_many.rb, line 7
      class HasAndBelongsToMany < CollectionAssociation
        def build
          reflection = super
          check_validity(reflection)
          define_destroy_hook
          reflection
        end
      end
    
    # File activerecord/lib/active_record/associations/builder/collection_association.rb, line 21
      class CollectionAssociation < Association
        def build
          wrap_block_extension
          reflection = super
          CALLBACKS.each { |callback_name| define_callback(callback_name) }
          reflection
        end
      end
    # File active_record/associations/association.rb
      class Association
        # build is not defined in this class.
      end
    

0 个答案:

没有答案