Hello there =)

I have the following:

class Location < ActiveRecord::Base
  has_many :operation_intervals_locations
  has_many :operation_intervals, :through => :operation_intervals_locations

  define_index "location" do
    # indexes here...

    # tried this syntax
    has operation_intervals(:start_int), :type => :integer 
    has operation_intervals(:end_int), :type => :integer
    has operation_intervals(:days_int), :type => :integer

    # and this one
    has operation_intervals.start_int, :type => :integer 
    has operation_intervals.end_int, :type => :integer
    has operation_intervals.days_int, :type => :integer
  end
end


class OperationInterval < ActiveRecord::Base
 attr_accessible :start_int, :end_int, :days_int  
end

I call Location.search("foo") to initialize the search

Then I do l = Location.first; l.name = "bar"; l.save(:validate=> false)

# joining is working just fine
OperationInterval Load (0.3ms)  SELECT `operation_intervals`.* FROM 
`operation_intervals` INNER JOIN `operation_intervals_locations` ON 
`operation_intervals`.`id` = 
`operation_intervals_locations`.`operation_interval_id` WHERE 
`operation_intervals_locations`.`location_id` = 1

# here's where I'm getting my crash
NoMethodError: undefined method `end_int' for 
#<ActiveRecord::Relation:0xe048450>
from 
/usr/local/rvm/gems/ruby-1.9.3-p194@rails326/gems/activerecord-3.2.6/lib/active_record/relation/delegation.rb:45:in
 `method_missing'

I tracked the bug and basically this is what I found out:

In 
/usr/local/rvm/gems/ruby-1.9.3-p194@rails326/gems/thinking-sphinx-2.0.12/lib/thinking_sphinx/attribute.rb
 

in def live_value , when object.send(method) is called, operation_intervals 
returns an array of operation intervals.

When the last line is called ( sphinx_value object.send(column.__name) ) , 
object doesn't have column.__name as attribute (object[0] does though) ... 
which leads to crashing.

Adding this code stops the crash but I think data will be missing from the 
index:

if (object.class == Array)
  object = object[0]
end

I JUST realized that operation_intervals(:days_int) 's type is not "integer" 
but should rather be "Array".

Is there a way we can raise an exception in live_value before the last line if 
the type is an Array? This would have saved me a few hours looking for this bug 
=)

Thank you very much!


Best,

A





-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/thinking-sphinx/-/x69kzkpSCMEJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/thinking-sphinx?hl=en.

Reply via email to