Skip to content

Commit

Permalink
* Applied bug fix from http://github.com/skanev/searchlogic to make #…
Browse files Browse the repository at this point in the history
…order work with association ordering.
  • Loading branch information
binarylogic committed Jul 28, 2009
1 parent 5134843 commit 64053d5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.rdoc
@@ -1,3 +1,7 @@
== 2.1.13

* Applied bug fix from http://github.com/skanev/searchlogic to make #order work with association ordering.

== 2.1.12 released 2009-07-28

* Fixed bug when dealing with scopes that return nil.
Expand Down
4 changes: 4 additions & 0 deletions lib/searchlogic/named_scopes/association_ordering.rb
Expand Up @@ -2,6 +2,10 @@ module Searchlogic
module NamedScopes
# Handles dynamically creating named scopes for associations.
module AssociationOrdering
def association_ordering_condition?(name)
!association_ordering_condition_details(name).nil?
end

private
def method_missing(name, *args, &block)
if details = association_ordering_condition_details(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/searchlogic/named_scopes/ordering.rb
Expand Up @@ -24,7 +24,7 @@ def order_condition?(name) # :nodoc:
def method_missing(name, *args, &block)
if name == :order
named_scope name, lambda { |scope_name|
return {} if !order_condition?(scope_name)
return {} if !order_condition?(scope_name) && !association_ordering_condition?(scope_name)
send(scope_name).proxy_options
}
send(name, *args)
Expand Down
4 changes: 4 additions & 0 deletions spec/named_scopes/association_ordering_spec.rb
Expand Up @@ -20,4 +20,8 @@
it "should ascend with a belongs to" do
User.ascend_by_company_name.proxy_options.should == Company.ascend_by_name.proxy_options.merge(:joins => :company)
end

it "should work through #order" do
Company.order('ascend_by_users_username').proxy_options.should == Company.ascend_by_users_username.proxy_options
end
end

0 comments on commit 64053d5

Please sign in to comment.