#79 ✓resolved
john (at psynix)

"undefined method `abstract_class?' for Object:Class" with collectiveidea-awesome_nested_set and searchlogic

Reported by john (at psynix) | April 1st, 2009 @ 07:41 AM

I've run into a slight incompatibility with awesome_nested_set (1.1.1), searchlogic (1.6.4) and scoped acts_as_nested_set.

With everything in place:

class SomeModel < ActiveRecord::Base
  acts_as_nested_set :scope => :account

Calling any nested set method fails with:

NoMethodError: undefined method `abstract_class?' for Object:Class
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:2212:in `class_of_active_record_descendant'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1467:in `base_class'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1143:in `reset_table_name'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1139:in `table_name'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1276:in `columns'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/base.rb:1289:in `column_names'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/conditions/base.rb:106:in `needed?'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/search/base.rb:37:in `needed?'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:159:in `filter_options_with_searchlogic'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/searchlogic-1.6.4/lib/searchlogic/active_record/base.rb:46:in `with_scope'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:94:in `named_scope'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:177:in `call'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/named_scope.rb:177:in `method_missing'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/collectiveidea-awesome_nested_set-1.1.1/lib/awesome_nested_set.rb:312:in `self_and_descendants'
from /opt/ruby-enterprise-1.8.6-20090201/lib/ruby/gems/1.8/gems/collectiveidea-awesome_nested_set-1.1.1/lib/awesome_nested_set.rb:319:in `descendants'

If I remove either the :scope on the nested set or the searchlogic config.gem (installing as a plugin makes no diff btw) then it won't generate any errors.



Comments and changes to this ticket

  • john (at psynix)

    john (at psynix) April 1st, 2009 @ 07:53 AM

    Sorry, forgot to mention that I'm using Rails v2.3.2.

  • Ben Johnson

    Ben Johnson April 16th, 2009 @ 03:30 AM

    • State changed from “new” to “open”

    Yeah that's strange, search logic build on the defaults of active record, so those plugins change default I would imagine something might not go right. I'll try t out in my console and see what i come up with.

  • mtyaka

    mtyaka May 23rd, 2009 @ 05:38 PM

    • Tag set to anonymous scope, awesome_nested_set, patch, scopes

    I also came across this problem when using the awesome_nested_set plugin. I didn't use the :scope option and most of the things worked fine except some nested set methods like siblings, left_sibling, etc.

    I tracked the problem down to anonymous scopes (awesome_nested_set uses them a lot internally). Chained anonymous scopes are the reason for the above error. This fails:

    MyModel.scoped({:conditions => {:id => 1}).scoped(:order => :id)

    scoped which looks like a method is in fact just a named_scope, defined in ActiveRecord::Base as:

    named_scope :scoped, lambda { |scope| scope }

    The problem is that named scope "scoped" is defined in the context of ActiveRecord::Base and not in the context of its subclass (e.g. MyModel). Searchlogic hooks into AR methods and expects self to be MyModel, not ActiveRecord::Base.

    I found out I could avoid this problem if I redefined the "scoped" named scope in my models:

    class MyModel < ActiveRecord::Base
      named_scope :scoped, lambda { |scope| scope }

    I am attaching a patch that extends AR's inherited method and automatically redefines scoped named scope on subclasses of ActiveRecord::Base.

  • Ben Johnson

    Ben Johnson July 30th, 2009 @ 01:38 PM

    • State changed from “open” to “resolved”

    This should be fixed in 2.0. Thanks!

  • ErikMitchell

    ErikMitchell October 10th, 2019 @ 11:24 AM

    Logic and rate of the house are defined for the approval of the terms for the citizens. The tinge of the green and ‌‌superiorpapers.com reviews is upheld for the flow of their forms for the humans. the picture is ousted for the erosion of the terms for the good and all blocked items for the respect for the people for the future offs for the candidates.

  • followersuk

    followersuk November 21st, 2019 @ 11:23 AM

    Searchlogic order does not overwrite ... was created by Remo Fritzsche ... for Object:Class" with collectiveidea-awesome_nested_set and searchlogic was ...
    by buyfollowersuk

  • HoustonHacker

    HoustonHacker February 5th, 2020 @ 07:49 AM

    it is decent not to mention meanful. it is fascinating blog page. Back-links is really effective detail. you possess in fact made it easier many of us what individuals explore blog page and put up these products usefull advice.
    best CBD oil for anxiety

  • Munna

    Munna July 3rd, 2020 @ 05:32 AM

    Get over here o know more about windows 10 operating system. windows 10 image download This is an awesome post for the user of windows 10 operating system.

  • jeni

    jeni September 30th, 2020 @ 05:50 AM

    Your post is too amazing. I have found with ease what I was looking for. Moreover, the content quality is awesome. Thanks for the nudge!

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

Provides common named scopes and object based searching.

People watching this ticket