searchlogic icon indicating copy to clipboard operation
searchlogic copied to clipboard

stack level too deep in merge_scopes_with_or

Open dougalcorn opened this issue 15 years ago • 2 comments

Class Message < ActiveRecord::Base
  has_many :addresses, :class_name => "MessageAddress"
  named_scope :system,  :joins => 'LEFT JOIN message_addresses ON message_addresses.message_id = messages.id', :conditions => 'message_addresses.id IS NULL'
end

Class MessageAddress < ActiveRecord::Base
  belongs_to :message
  belongs_to :recipeint, :polymorphic => true
  named_scope :for_user, lambda { |user| { :conditions => ["blah blah blah", user] } }
end

Now when I do Message.addresses_for_user_or_system(user) It generates a stack level too deep.

    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `send'                                                                                                                                                     
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `merge_scopes_with_or'                                                                                                                                     
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `collect'                                                                                                                                                  
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `merge_scopes_with_or'                                                                                                                                     
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:99:in `create_or_condition'                                                                                                                                       
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `send'                                                                                                                                                     
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `merge_scopes_with_or'                                                                                                                                     
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `collect'                                                                                                                                                  
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:104:in `merge_scopes_with_or'                                                                                                                                     
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:99:in `create_or_condition'                                                                                                                                       
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:22:in `addresses_for_user_or_without_addresses'                                                                                                                   
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:22:in `send'                                                                                                                                                      
    searchlogic (2.3.1) [v] lib/searchlogic/named_scopes/or_conditions.rb:22:in `method_missing'                                                                                                                                            
    vendor/gems/mislav-will_paginate-2.3.11/lib/will_paginate/finder.rb:170:in `method_missing'                                                                                                                                             
    app/models/message.rb:19:in `for_user'                                                                                                                                                                                                  

There's a couple problems here. Obviously there's a bug that causes the stack level too deep. But the or using an associated named scope seems to be completely unsupported. So maybe my answer is to just not do that. Oh, and I manually patched my searchlogic 2.3.1 with the latest version of or_condition.rb

dougalcorn avatar Sep 11 '09 17:09 dougalcorn

Yeah, association support is coming, I'm working out a couple of issues. I'll throw this in the test suite.

ghost avatar Sep 12 '09 05:09 ghost

Searchlogic really is great. We're making a lot of use out of it. In this case we ended up just writing our own named scope: break out the sql!

dougalcorn avatar Sep 12 '09 13:09 dougalcorn