Hello everybody, I'm having troubles trying to user sphinx_scope.
I need to order the results of a query by a column of an associated
table y I think sphinx_scope may help, Let's me explain the situation:

I got two objects called Expedientes and Movimientos.

Expedientes:
id integer
numero integer
fechaentrada date
...

Movimientos
id integer
expediente_id integer
fecharecepcion date
horarecepcion time
...

I need to query an Expediente and order by the column
Movimiento.fecharecepcion and Movimiento.horarecepcion in DESC order.

I create a sphinx_scope in Expediente's model:

sphinx_scope(:ordenado_por_fecharecepcion) {
    {:include => :movimientos}
    {:order => 'movimientos.fecharecepcion DESC'}
  }

In the Controller, where I perform the query:

@expedientes = Expediente.ordenado_por_fecharecepcion.search(buscar,
                                              :include => :expediente,
                                              :conditions => {:numero
=> "#{anyo_busq}*", :estado_id => estado, :oficinaactual_id =>
oficina_id },#['numero = ?, expeentradas.estado:id = ?,
oficinaactual_id = ?', "#{anyo_busq}*", estado, oficina_id],
                                              :page => params[:page],
                                              :per_page => 10)

How you can see I using some conditions to perform the query, I tryeid
on console with Expediente.search('something') and returned me
results, but when I try like this
Expediente.ordenado_por_fecharecepcion.search('something') didn't
return nothing.

If there another way to do what I'm trying please make know.

Thanks any help in advance.

P.D.: Sorry my bad english.
--~--~---------~--~----~------------~-------~--~----~
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