#120 new
David Tong

undefined method for Polymorphic association using Searchlogic

Reported by David Tong | March 1st, 2010 @ 01:24 AM

I am unable to call a polymorphic scope using the searchlogic plugin as it keeps on returning 'undefined method'. I am certain it is only a problem within my project as I created a test project and I was able to call a polymorphic scope using the searchlogic plugin.

I am hoping someone can provide a suggestion on how to debug this issue.

My project consists of several gems, and is using Rails v2.3.4 and the latest searchlogic repository.

Thanks in advance.

Polymorphic model association

class Timesheet < ActiveRecord::Base
  has_many  :timesheet_entries, :as => :timesheet_enterable

class TimesheetEntry < ActiveRecord::Base
  belongs_to  :timesheet
  belongs_to  :timesheet_enterable, :polymorphic => true

class Task < ActiveRecord::Base
  has_many  :timesheet_entries, :as => :timesheet_enterable

Console results

TimesheetEntry.timesheet_enterable_type_equals("Task").size

=> 39649

TimesheetEntry.timesheet_enterable_id_equals("100").size

=> 9

Task.project_id_equals(217).size

=> 16

TimesheetEntry.timesheet_enterable_task_type_project_id_equals(217).entry_type_equals("project")

NoMethodError: undefined method `timesheet_enterable_task_type_project_id_equals' for #<Class:0x36bd660>

from /Users/chino/Documents/git/isf001/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/conditions.rb:88:in `method_missing'

from /Users/chino/Documents/git/isf001/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/association_conditions.rb:19:in `method_missing'

from /Users/chino/Documents/git/isf001/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/association_ordering.rb:27:in `method_missing'

from /Users/chino/Documents/git/isf001/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/ordering.rb:30:in `method_missing'

from /Users/chino/Documents/git/isf001/vendor/plugins/searchlogic/lib/searchlogic/named_scopes/or_conditions.rb:28:in `method_missing'

from /Users/chino/Documents/git/isf001/vendor/rails/activerecord/lib/active_record/base.rb:1959:in `method_missing_without_paginate'

from /Users/chino/Documents/git/isf001/vendor/plugins/will_paginate/lib/will_paginate/finder.rb:170:in `method_missing'

from (irb):16

from :0

Comments and changes to this ticket

  • David Tong

    David Tong March 1st, 2010 @ 10:40 PM

    Gotchya!

    class Timesheet < ActiveRecord::Base
      has_many  :timesheet_entries, :as => :timesheet_enterable
    
    class TimesheetEntry < ActiveRecord::Base
      belongs_to  :timesheet
      belongs_to  :timesheet_enterable, :polymorphic => true
    
    class Task < ActiveRecord::Base
      has_many  :timesheet_entries, :as => :timesheet_enterable
    

    Renaming the polymorphic asociation from :timesheet_enterable to :time_enterable fixed the problem.

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

Pages