You are absolutely right. I removed the :type option for my from_ and
to_date attributes in define_index and it seems to be working fine for
the dates...

(i got another problem though, I'll post again if I can't solve it
myself)

Thank you so much for your prompt answer!
Cheers,
Alex

On Feb 27, 2:00 pm, Pat Allan <[email protected]> wrote:
> Hi Alex, Clemens
>
> Firstly - there's no difference between tracks(:from_date) and 
> tracks.from_date - the former syntax is to avoid issues with reserved methods 
> in Ruby, but functionally the code underneath is the same.
>
> Secondly, I'm pretty sure the issue is because you're trying to cast an array 
> of times into a single time with your :type => :datetime. Sphinx doesn't have 
> the concept of multi-value datetime attributes, just multi-value integer 
> attributes... but it *does* store datetimes as integer timestamps. Thinking 
> Sphinx should allow for this too.
>
> So: does it all work smoothly if you remove the explicit :type option in the 
> attribute definition?
>
> Cheers
>
> --
> Pat
>
> On 28/02/2011, at 4:50 AM, alex wrote:
>
>
>
>
>
>
>
> > Hi Clemens,
>
> > Thanks for your reply. Just tried your suggestion and got the same
> > result as what I had before.... So I need to dig further!
>
> > Also, here is the exact error message I get:
> >  Track Load (0.5ms)   SELECT * FROM `tracks` WHERE
> > (`tracks`.course_id = 1949) ORDER BY tracks.from_date
>
> > NoMethodError (undefined method `from_date' for #<Array:0x106ce8388>):
> >  /usr/local/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.3/lib/
> > thinking_sphinx/attribute.rb:188:in `live_value'
> >  /usr/local/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.3/lib/
> > thinking_sphinx/active_record/attribute_updates.rb:37:in
> > `attribute_values_for_index'
> >  /usr/local/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.3/lib/
> > thinking_sphinx/active_record/attribute_updates.rb:36:in `each'
> >  /usr/local/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.3/lib/
> > thinking_sphinx/active_record/attribute_updates.rb:36:in `inject'
> >  /usr/local/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.3/lib/
> > thinking_sphinx/active_record/attribute_updates.rb:36:in
> > `attribute_values_for_index'
> >  /usr/local/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.3/lib/
> > thinking_sphinx/active_record/attribute_updates.rb:17:in
> > `update_attribute_values'
> >  /usr/local/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.3/lib/
> > thinking_sphinx/active_record/attribute_updates.rb:16:in `each'
> >  /usr/local/lib/ruby/gems/1.8/gems/thinking-sphinx-1.4.3/lib/
> > thinking_sphinx/active_record/attribute_updates.rb:16:in
> > `update_attribute_values'
> >  /usr/local/lib/ruby/gems/1.8/gems/after_commit-1.0.8/lib/
> > after_commit/connection_adapters.rb:129:in `send'
> >  /usr/local/lib/ruby/gems/1.8/gems/after_commit-1.0.8/lib/
> > after_commit/connection_adapters.rb:129:in
> > `trigger_after_commit_callbacks'
> >  /usr/local/lib/ruby/gems/1.8/gems/after_commit-1.0.8/lib/
> > after_commit/connection_adapters.rb:128:in `each'
> >  /usr/local/lib/ruby/gems/1.8/gems/after_commit-1.0.8/lib/
> > after_commit/connection_adapters.rb:128:in
> > `trigger_after_commit_callbacks'
> >  /usr/local/lib/ruby/gems/1.8/gems/after_commit-1.0.8/lib/
> > after_commit/connection_adapters.rb:36:in `commit_db_transaction'
> >  /usr/local/lib/ruby/gems/1.8/gems/after_commit-1.0.8/lib/
> > after_commit/connection_adapters.rb:12:in `transaction'
> >  app/controllers/courses/tracks_controller.rb:117:in `create'
>
> > Rendered rescues/_trace (265.1ms)
>
> > Not sure if that helps...
>
> > Alex
>
> > On Feb 27, 9:16 am, Clemens Kofler <[email protected]> wrote:
> >> Hi Alex,
>
> >> I could be wrong here but the correct syntax should be tracks.from_date 
> >> instead of tracks(:from_date). You only need the parenthesized syntax when 
> >> indexing columns with "special" meaning (e.g. id and name).
>
> >> HTH,
> >> - Clemens
>
> >> On Feb 27, 2011, at 6:12 PM, alex wrote:
>
> >>> Hi,
>
> >>> I have the following models:
>
> >>> Track
> >>>  belongs_to course, :touch => true
>
> >>> Course
> >>>  has_many tracks, :dependent => :destroy, :order =>
> >>> "tracks.from_date"
>
> >>>  define_index do
> >>>    ....
> >>>    has  tracks(:from_date), :as => :track_from_dates, :type
> >>> => :datetime
> >>>    has  tracks(:to_date), :as => :track_to_dates, :type => :datetime
> >>>  end
>
> >>> Everything works fine when I don't have the "has tracks(:from/
> >>> to_date)". However, with these 2 lines, I have a bug when I do create
> >>> a Course (even if not track is associated to it), or when I try to
> >>> create or destroy a Track associated to a Course. In every case, the
> >>> Course and Tracks are created and destroyed as planned, but I then get
> >>> the following error message:
>
> >>>  NoMethodError: undefined method `from_date' for #<Array:0x102962b90>
>
> >>> With error log involving activerecord-2.3.5, thinking-sphinx-1.3.11,
> >>> activesupport-2.3.5, after_commit-1.0.8.
>
> >>> I'm not sure where to look to debug it. Any idea?
>
> >>> Thanks!
>
> >>> --
> >>> You received this message because you are subscribed to the Google Groups 
> >>> "Thinking Sphinx" group.
> >>> 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 
> >>> athttp://groups.google.com/group/thinking-sphinx?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Thinking Sphinx" group.
> > 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 
> > athttp://groups.google.com/group/thinking-sphinx?hl=en.

-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
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