forked from mislav/will_paginate
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New named scope patches for 2.0.4 and 1.2.6. Change rake test_all to …
…use 2.0.4 vs 2.0.2. Add an empty setup ArrayPaginationTest so that fixtures are not loaded for this case in 1.2.6 tests.
- Loading branch information
1 parent
6b1fd99
commit af80782
Showing
5 changed files
with
82 additions
and
40 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
|
||
ActiveRecord::Associations::HasManyAssociation.class_eval do | ||
protected | ||
def method_missing(method, *args, &block) | ||
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) | ||
super | ||
elsif @reflection.klass.scopes.include?(method) | ||
@reflection.klass.scopes[method].call(self, *args) | ||
else | ||
create_scoping = {} | ||
set_belongs_to_association_for(create_scoping) | ||
|
||
@reflection.klass.with_scope( | ||
:create => create_scoping, | ||
:find => { | ||
:conditions => @finder_sql, | ||
:joins => @join_sql, | ||
:readonly => false | ||
} | ||
) do | ||
@reflection.klass.send(method, *args, &block) | ||
end | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Associations::HasManyThroughAssociation.class_eval do | ||
protected | ||
def method_missing(method, *args, &block) | ||
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) | ||
super | ||
elsif @reflection.klass.scopes.include?(method) | ||
@reflection.klass.scopes[method].call(self, *args) | ||
else | ||
@reflection.klass.with_scope(construct_scope) { @reflection.klass.send(method, *args, &block) } | ||
end | ||
end | ||
end | ||
|
||
ActiveRecord::Associations::HasAndBelongsToManyAssociation.class_eval do | ||
protected | ||
def method_missing(method, *args, &block) | ||
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) | ||
super | ||
elsif @reflection.klass.scopes.include?(method) | ||
@reflection.klass.scopes[method].call(self, *args) | ||
else | ||
@reflection.klass.with_scope(:find => { :conditions => @finder_sql, :joins => @join_sql, :readonly => false }) do | ||
@reflection.klass.send(method, *args, &block) | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
ActiveRecord::Associations::AssociationCollection.class_eval do | ||
protected | ||
def method_missing(method, *args) | ||
if @target.respond_to?(method) || (!@reflection.klass.respond_to?(method) && Class.respond_to?(method)) | ||
if block_given? | ||
super { |*block_args| yield(*block_args) } | ||
else | ||
super | ||
end | ||
elsif @reflection.klass.scopes.include?(method) | ||
@reflection.klass.scopes[method].call(self, *args) | ||
else | ||
with_scope(construct_scope) do | ||
if block_given? | ||
@reflection.klass.send(method, *args) { |*block_args| yield(*block_args) } | ||
else | ||
@reflection.klass.send(method, *args) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters