#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.

  • Mary741

    Mary741 February 4th, 2019 @ 06:45 AM

    Is this something to consider in a social networking site? If I would have say comments polymorphically associated with various models, wouldn't it be a major hit on one table all the time? myprepaidcenter

  • anonymous

    anonymous August 29th, 2019 @ 11:50 PM

    Here, in this article, I discovered all the most recent ability and you simply stunning. I truly making the most of your data which is generally identified with the music rivalry and most recent ability where you can buy essay club review for quality work. You doing the astounding activity and I truly respect you.

  • Ahmadkhan

    Ahmadkhan February 28th, 2020 @ 06:33 AM

    Its speed can be influenced by the waste-gate valve, which is controlled by the pressure-driven Decimal to Scientific Notation Converter.
    Decimal to Scientific Notation Converter

  • ahmadkha07

    ahmadkha07 March 15th, 2020 @ 08:39 AM

    There are certainly a lot of very 50 most beautiful women here that are drawn by the bright lights.
    50.most popular women

  • ahmadkha07

    ahmadkha07 March 15th, 2020 @ 08:41 AM

    There are certainly a lot of very 50 most beautiful women here that are drawn by the bright lights.
    50.most popular women

  • Andrew Piana

    Andrew Piana June 10th, 2020 @ 07:39 AM

    Is this something to consider in a social networking site? If I would have say comments polymorphically associated with various models, wouldn't it be a major hit on one table all the time? myprepaidcenter

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

Attachments

Pages