mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Undeprecate the :extend option
Suggested by @dhh. It doesn't affect the generated SQL, so seems reasonable to continue to allow it as an association option.
This commit is contained in:
parent
5f759ff063
commit
5937bd02de
6 changed files with 30 additions and 3 deletions
|
@ -985,7 +985,6 @@
|
||||||
|
|
||||||
* `:conditions` becomes `:where`.
|
* `:conditions` becomes `:where`.
|
||||||
* `:include` becomes `:includes`.
|
* `:include` becomes `:includes`.
|
||||||
* `:extend` becomes `:extending`.
|
|
||||||
|
|
||||||
The code to implement the deprecated features has been moved out to
|
The code to implement the deprecated features has been moved out to
|
||||||
the `activerecord-deprecated_finders` gem. This gem is a dependency
|
the `activerecord-deprecated_finders` gem. This gem is a dependency
|
||||||
|
|
|
@ -25,5 +25,5 @@ Gem::Specification.new do |s|
|
||||||
s.add_dependency 'activemodel', version
|
s.add_dependency 'activemodel', version
|
||||||
|
|
||||||
s.add_dependency 'arel', '~> 3.0.2'
|
s.add_dependency 'arel', '~> 3.0.2'
|
||||||
s.add_dependency 'activerecord-deprecated_finders', '0.0.1'
|
s.add_dependency 'activerecord-deprecated_finders', '0.0.2'
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,6 +16,7 @@ module ActiveRecord
|
||||||
def scope
|
def scope
|
||||||
scope = klass.unscoped
|
scope = klass.unscoped
|
||||||
scope.merge! eval_scope(klass, reflection.scope) if reflection.scope
|
scope.merge! eval_scope(klass, reflection.scope) if reflection.scope
|
||||||
|
scope.extending! Array(options[:extend])
|
||||||
add_constraints(scope)
|
add_constraints(scope)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,8 @@ module ActiveRecord::Associations::Builder
|
||||||
CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove]
|
CALLBACKS = [:before_add, :after_add, :before_remove, :after_remove]
|
||||||
|
|
||||||
def valid_options
|
def valid_options
|
||||||
super + [:table_name, :finder_sql, :counter_sql, :before_add, :after_add, :before_remove, :after_remove]
|
super + [:table_name, :finder_sql, :counter_sql, :before_add,
|
||||||
|
:after_add, :before_remove, :after_remove, :extend]
|
||||||
end
|
end
|
||||||
|
|
||||||
attr_reader :block_extension, :extension_module
|
attr_reader :block_extension, :extension_module
|
||||||
|
|
|
@ -1717,4 +1717,16 @@ class HasManyAssociationsTest < ActiveRecord::TestCase
|
||||||
author = authors(:mary)
|
author = authors(:mary)
|
||||||
assert !author.first_posts.exists?
|
assert !author.first_posts.exists?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "association with extend option" do
|
||||||
|
post = posts(:welcome)
|
||||||
|
assert_equal "lifo", post.comments_with_extend.author
|
||||||
|
assert_equal "hello", post.comments_with_extend.greeting
|
||||||
|
end
|
||||||
|
|
||||||
|
test "association with extend option with multiple extensions" do
|
||||||
|
post = posts(:welcome)
|
||||||
|
assert_equal "lifo", post.comments_with_extend_2.author
|
||||||
|
assert_equal "hello", post.comments_with_extend_2.greeting
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -5,6 +5,12 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module NamedExtension2
|
||||||
|
def greeting
|
||||||
|
"hello"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
scope :containing_the_letter_a, -> { where("body LIKE '%a%'") }
|
scope :containing_the_letter_a, -> { where("body LIKE '%a%'") }
|
||||||
scope :ranked_by_comments, -> { order("comments_count DESC") }
|
scope :ranked_by_comments, -> { order("comments_count DESC") }
|
||||||
|
|
||||||
|
@ -43,6 +49,14 @@ class Post < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
has_many :comments_with_extend, extend: NamedExtension, class_name: "Comment", foreign_key: "post_id" do
|
||||||
|
def greeting
|
||||||
|
"hello"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
has_many :comments_with_extend_2, extend: [NamedExtension, NamedExtension2], class_name: "Comment", foreign_key: "post_id"
|
||||||
|
|
||||||
has_many :author_favorites, :through => :author
|
has_many :author_favorites, :through => :author
|
||||||
has_many :author_categorizations, :through => :author, :source => :categorizations
|
has_many :author_categorizations, :through => :author, :source => :categorizations
|
||||||
has_many :author_addresses, :through => :author
|
has_many :author_addresses, :through => :author
|
||||||
|
|
Loading…
Reference in a new issue