Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#search ignores :order argument on associations which have an order defined #15

Open
ghost opened this issue Aug 7, 2009 · 3 comments

Comments

@ghost
Copy link

ghost commented Aug 7, 2009

Consider a class Foo, with associated Bars:

@@@ ruby
class Foo < ActiveRecord::Base
has_many :bars, :order => :name
end
@@@

If you do:

@@@ ruby
Foo.bars.search(:order => "ascend_by_size").all
@@@

The results are still sorted by :name -- i.e. the "ascend_by_size" :order argument to the #search method is ignored.

The SQL query looks like:

@@@ sql
SELECT * FROM bars WHERE bars.foo_id = 1 ORDER BY bars.name;
@@@

Is this a bug?

original LH ticket

This ticket has 0 attachment(s).

@ghost
Copy link
Author

ghost commented Aug 7, 2009

#search ignores :order argument on associations which have an order defined

Hmm, I’m not sure, let me add a failing test and play around with it. If you want fork the project and write a quick failing test. It looks like the Searchlogic::Search#current_scope is taking priority.

by Ben Johnson

@mig
Copy link

mig commented Sep 10, 2009

Here is a failing spec: It's running through a defined named_scope, same issue though:

it "should overwrite ordering through a named_scope" do
  %w(bjohnson thunt).each { |username| User.create(:username => username) }
  User.class_eval {
    named_scope :by_username, :order => "username DESC"
  }
  User.by_username.ascend_by_username.should == User.all(:order => "username ASC")
end

@mig
Copy link

mig commented Sep 11, 2009

Hmm, looks like this is the same problem as http://github.com/binarylogic/searchlogic/issues#issue/17 which is an AR problem, not a searchlogic one

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant