binarylogic / searchlogic

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

Search Logic named_scope through association fails #144

Closed Kr00lIX closed 13 years ago

Kr00lIX commented 13 years ago

Create a project

rails searchlogic_test
cd searchlogic_test

script/generate model category name:string
script/generate model product category_id:integer name:string

Add to db/seeds.rb

Category.create(:name=>"first category")

Setup the database

rake db:migrate
rake db:seed

Add to config/environment.rb

config.gem "searchlogic"

Models

app/models/product.rb

class Product < ActiveRecord::Base
  belongs_to :category
  named_scope :some_scope, {:conditions=>{:name=>""}}
end

app/models/category.rb

class Category < ActiveRecord::Base
  has_many :products
end

Setup the database

rake db:migrate
rake db:seed

Test on console

script/console

Category.first.products.some_scope.ascend_by_created_at NoMethodError: undefined method ascend_by_created_at' for []:Array from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:149:insend' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:149:in send' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/named_scope.rb:186:inmethod_missing' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/base.rb:2182:in with_scope' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:207:insend' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/associations/association_proxy.rb:207:in with_scope' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/named_scope.rb:118:insend' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/named_scope.rb:118:in with_scope' from /home/../.rvm/gems/ree-1.8.7-2010.02@fotoshkola/gems/activerecord-2.3.11/lib/active_record/named_scope.rb:179:inmethod_missing' from (irb):16 but Category.first.products.ascend_by_created_at.some_scope - works correct

Kr00lIX commented 13 years ago

This issue was fixed in the version 2.5.4