[Prev] Thread [Next]  |  [Prev] Date [Next]

[ts] indexing association - has_one Brian M Tue Aug 24 18:00:36 2010

I'm having trouble indexing a has_one association with order.  It
seems like the order that makes my has_one work (and return the most
recent one) isn't being carried though to the Sphinx SQL.

I have a document model that has_many revisions.  I'd like to include
the search_text field from the current_revision on my document index.
To do this, I setup an association on the document model and reflected
the association in my index:

has_one :current_revision, :class_name => "Revision", :order =>
'position DESC'

define_index do
  indexes title
  indexes description
  indexes current_revision(:search_text), :as => :revision_text

Generating something like:

SELECT SQL_NO_CACHE `documents`.`id` * 2 + 1 AS `id` ,
`documents`.`title` AS `title`, `documents`.`description` AS
`description`, `revisions`.`search_text` AS `revision_text`,
`documents`.`id` AS `sphinx_internal_id`, 555739168 AS `class_crc`, 0
AS `sphinx_deleted` FROM `documents`    LEFT OUTER JOIN `revisions` ON
revisions.document_id = documents.id  WHERE `documents`.`id` >= $start
AND `documents`.`id` <= $end GROUP BY `documents`.`id`  ORDER BY NULL

When I test that it consistently returns the search_text from the
earliest revision, ignorant of my position DESC statement.  Is this
something that Sphinx can handle or should I hack around and add a
is_current_revision field to the revisions table (conditions on a
has_one worked in testing)?

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