#36 ✓resolved
Yaraher

klass.metaclass.class_eval

Reported by Yaraher | December 3rd, 2008 @ 08:56 PM

I'm currently trying Searchlogic but have find to have some issues making it work properly.

After installing it (either by using gem or plugin) it get this error when starting my server:


/Users/alvaropereyrarabanal/Development/SK/vendor/plugins/binarylogic-searchlogic/lib/
searchlogic/conditions/magic_methods.rb:8:in `included': undefined method `metaclass' for
Searchlogic::Conditions::Base:Class (NoMethodError)

which mentions this line:


      def self.included(klass)
        klass.metaclass.class_eval do
          include ClassMethods
          attr_accessor :added_column_equals_conditions, :added_associations
        end

I tried changing the line to


      def self.included(klass)
        klass.class_eval do
          include ClassMethods
          attr_accessor :added_column_equals_conditions, :added_associations
        end

and that seemed to at least let me run. However, when trying to search something with it, it can't find the added_associations from my product model (which is obviously something that must be added on the line I modified):


NoMethodError (undefined method `added_associations' for Searchlogic::Cache::ProductConditions:Class):

Is there something wrong I'm doing when trying to start Searchlogic?

Comments and changes to this ticket

  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 09:18 PM

    • State changed from “new” to “resolved”

    I'm assuming you are using an older version rails that doesn't have meta class. Update from the repository, it should work now. Let me know if you have any probs.

  • Yaraher

    Yaraher December 3rd, 2008 @ 09:25 PM

    That did the trick. However, when trying to do a Product search, I get this error:

    
                search = Product.new_search
                search.conditions.or_name_contains = params["q"]
                search.conditions.or_description_contains = params["q"]
                search.conditions.or_code_contains = params["q"]
                @catalogue = search.all
    
    
    NoMethodError (You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.class_name):
        /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/reflection.rb:220:in `derive_class_name'
        /Library/Ruby/Gems/1.8/gems/activerecord-2.1.0/lib/active_record/reflection.rb:106:in `class_name'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:59:in `add_associations!'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:55:in `each'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:55:in `add_associations!'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:46:in `initialize'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/search/conditions.rb:17:in `new'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/search/conditions.rb:17:in `initialize'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:140:in `new'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:140:in `searchlogic_search'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:65:in `new_search'
        /app/controllers/catalogue_controller.rb:126:in `__instance_exec0'
    
  • Ben Johnson

    Ben Johnson December 3rd, 2008 @ 09:32 PM

    It looks like you found a old bug in ActiveRecord. Do you have a funny relationship or something? Because that is a bug had been fixed in later versions. Could you update to 2.1.2 at least? Because there is nothing I can do about that.

  • Yaraher

    Yaraher December 3rd, 2008 @ 09:33 PM

    I'm currently working with 2.1.0. Will try updating then. Thanks!

  • Yaraher

    Yaraher December 3rd, 2008 @ 09:38 PM

    Just updated to 2.1.2 and still shows the

    
    NoMethodError (You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.class_name):
        /Library/Ruby/Gems/1.8/gems/activerecord-2.1.2/lib/active_record/reflection.rb:224:in `derive_class_name'
        /Library/Ruby/Gems/1.8/gems/activerecord-2.1.2/lib/active_record/reflection.rb:106:in `class_name'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:59:in `add_associations!'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:55:in `each'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:55:in `add_associations!'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:46:in `initialize'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/search/conditions.rb:17:in `new'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/search/conditions.rb:17:in `initialize'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:140:in `new'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:140:in `searchlogic_search'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:65:in `new_search'
        /app/controllers/catalogue_controller.rb:126:in `__instance_exec0'
    
  • Yaraher

    Yaraher December 3rd, 2008 @ 09:42 PM

    Even on 2.2.2 (it was time to do it anyway) shows the

    
    NoMethodError (You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.class_name):
        /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:303:in `derive_class_name'
        /Library/Ruby/Gems/1.8/gems/activerecord-2.2.2/lib/active_record/reflection.rb:107:in `class_name'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:59:in `add_associations!'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:55:in `each'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:55:in `add_associations!'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/conditions/magic_methods.rb:46:in `initialize'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/search/conditions.rb:17:in `new'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/search/conditions.rb:17:in `initialize'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:140:in `new'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:140:in `searchlogic_search'
        /vendor/plugins/binarylogic-searchlogic/lib/searchlogic/active_record/base.rb:65:in `new_search'
        /app/controllers/catalogue_controller.rb:126:in `__instance_exec0'
    

    error.

    Product have the following relationships:

    
     has_many :order_details
      has_many :orders, :through => :order_details
    
      has_many :quote_details
      has_many :quotes, :through => :quote_details, :order=>"created_at ASC"
    
      has_many :send_order_details
      has_many :send_orders, :through=>:send_order_details
    
      has_many :sending_guide_details
      has_many :sending_guides, :through=>:sending_guide_details
    
      has_many :input_order_details, :order=>"created_at DESC"
      has_many :input_orders, :through=>:input_order_details
      has_many :last_input_orders, :class_name => "InputOrderDetail", :order=>"order_date DESC", :limit=>5
    
      has_many :stores, :through => :input_order_details
      has_many :prices
      has_one :category
      belongs_to :unit
      belongs_to :category
      belongs_to :subcategory, :class_name=>"Category"
    
      belongs_to :brand
    
  • Yaraher

    Yaraher December 3rd, 2008 @ 10:30 PM

    After playing with some of the relationships, I find out the one of them was worthless.

    Thanks for your help. Now I hace another doubt, but will open another ticket for ir.

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

Tags

Pages