Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4206

Show
Ignore:
Timestamp:
04/11/06 01:10:42 (3 years ago)
Author:
rick
Message:

Allow multiple association extensions with :extend option (closes #4666) [Josh Susser]

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/activerecord/CHANGELOG

    r4203 r4206  
     1*SVN* 
     2 
     3* Allow multiple association extensions with :extend option (closes #4666) [Josh Susser] 
     4 
     5    class Account < ActiveRecord::Base 
     6      has_many :people, :extend => [FindOrCreateByNameExtension, FindRecentExtension] 
     7    end 
     8 
     9 
    110*1.14.2* (April 9th, 2005) 
    211 
  • trunk/activerecord/lib/active_record/associations.rb

    r4179 r4206  
    214214    #   class Company < ActiveRecord::Base 
    215215    #     has_many :people, :extend => FindOrCreateByNameExtension 
     216    #   end 
     217    # 
     218    # If you need to use multiple named extension modules, you can specify an array of modules with the :extend option. 
     219    # In the case of name conflicts between methods in the modules, methods in modules later in the array supercede 
     220    # those earlier in the array. Example: 
     221    # 
     222    #   class Account < ActiveRecord::Base 
     223    #     has_many :people, :extend => [FindOrCreateByNameExtension, FindRecentExtension] 
    216224    #   end 
    217225    # 
  • trunk/activerecord/lib/active_record/associations/association_proxy.rb

    r3961 r4206  
    99      def initialize(owner, reflection) 
    1010        @owner, @reflection = owner, reflection 
    11         proxy_extend(reflection.options[:extend]) if reflection.options[:extend] 
     11        Array(reflection.options[:extend]).each { |ext| proxy_extend(ext) } 
    1212        reset 
    1313      end 
  • trunk/activerecord/test/associations_extensions_test.rb

    r2897 r4206  
    1919    assert_equal projects(:action_controller), developers(:david).projects_extended_by_name.find_most_recent 
    2020  end 
     21 
     22  def test_named_two_extensions_on_habtm 
     23    assert_equal projects(:action_controller), developers(:david).projects_extended_by_name_twice.find_most_recent 
     24    assert_equal projects(:active_record), developers(:david).projects_extended_by_name_twice.find_least_recent 
     25  end 
    2126   
    2227  def test_marshalling_extensions 
  • trunk/activerecord/test/fixtures/developer.rb

    r2940 r4206  
    22  def find_most_recent 
    33    find(:first, :order => "id DESC") 
     4  end 
     5end 
     6 
     7module DeveloperProjectsAssociationExtension2 
     8  def find_least_recent 
     9    find(:first, :order => "id ASC") 
    410  end 
    511end 
     
    1723      :association_foreign_key => "project_id", 
    1824      :extend => DeveloperProjectsAssociationExtension 
     25 
     26  has_and_belongs_to_many :projects_extended_by_name_twice,  
     27      :class_name => "Project",  
     28      :join_table => "developers_projects",  
     29      :association_foreign_key => "project_id", 
     30      :extend => [DeveloperProjectsAssociationExtension, DeveloperProjectsAssociationExtension2] 
    1931 
    2032  has_and_belongs_to_many :special_projects, :join_table => 'developers_projects', :association_foreign_key => 'project_id'