binarylogic / searchlogic

Searchlogic provides object based searching, common named scopes, and other useful tools.
http://rdoc.info/projects/binarylogic/searchlogic
MIT License
1.39k stars 133 forks source link

doesn't work with rails default_scope #56

Open spovich opened 14 years ago

spovich commented 14 years ago

Bug or just fundamental incompatibility w/rails default_scope? If I declare a default_scope on my model, none of the rails_helpers for click-sort column headings will work.

The search object is built up correctly, but rails clobbers it w/the default scope.

I can work around this by declaring default sort criteria in the controller where the search object is created, but the only thing I don't like is how the the default_scope silently kills your searchlogic search.

Any thoughts?

etaque commented 14 years ago

same bug and same workaround for me.

tilsammans commented 14 years ago

i created a failing spec for this bug here: http://github.com/tilsammans/searchlogic/commit/c7be7da17300796b5a93f5173c9539afd0f8ae4f

and plan on attacking the bug itself next. can't quite wrap my mind around it yet though.

etaque commented 14 years ago

By the way, :order on a default scope can't be overriden by the :order of a named_scope, and Searchlogic is based on named_scopes. So, that's probably an ActiveRecord bug/feature.

tilsammans commented 14 years ago

Where did you get that idea? The outermost named_scope clobbers any default scope.

Fixed this in my fork: commit http://github.com/tilsammans/searchlogic/commit/c03a3bfd35dae543d3c3a3e258c187e7edd2ad3d

will send a pull request to binarylogic

etaque commented 14 years ago

From this ticket: https://rails.lighthouseapp.com/projects/8994/tickets/2346-named_scope-doesnt-override-default_scopes-order-key

But I may be misleading 'cause I don't know ActiveRecord plumbing enough for the moment. Hope your patch will resolve it.