mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Propagate association extensions to scopes called on the association.
Signed-off-by: Santiago Pastorino <santiago@wyeworks.com>
This commit is contained in:
parent
817e370136
commit
6bd9fac1e3
3 changed files with 9 additions and 0 deletions
|
@ -188,6 +188,9 @@ module ActiveRecord
|
|||
if select = select_value
|
||||
scope = scope.select(select)
|
||||
end
|
||||
if Relation === scope
|
||||
scope = scope.extending(*Array.wrap(@reflection.options[:extend]))
|
||||
end
|
||||
scope.where(construct_owner_conditions)
|
||||
end
|
||||
|
||||
|
|
|
@ -29,6 +29,11 @@ class AssociationsExtensionsTest < ActiveRecord::TestCase
|
|||
assert_equal projects(:action_controller), developers(:david).projects_extended_by_name_and_block.find_most_recent
|
||||
assert_equal projects(:active_record), developers(:david).projects_extended_by_name_and_block.find_least_recent
|
||||
end
|
||||
|
||||
def test_extension_with_scopes
|
||||
assert_equal comments(:greetings), posts(:welcome).comments.offset(1).find_most_recent
|
||||
assert_equal comments(:greetings), posts(:welcome).comments.not_again.find_most_recent
|
||||
end
|
||||
|
||||
def test_marshalling_extensions
|
||||
david = developers(:david)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
class Comment < ActiveRecord::Base
|
||||
scope :limit_by, lambda {|l| limit(l) }
|
||||
scope :containing_the_letter_e, :conditions => "comments.body LIKE '%e%'"
|
||||
scope :not_again, where("comments.body NOT LIKE '%again%'")
|
||||
scope :for_first_post, :conditions => { :post_id => 1 }
|
||||
scope :for_first_author,
|
||||
:joins => :post,
|
||||
|
|
Loading…
Reference in a new issue