I have these sql code in postgresql
“SELECT * from convenios where id NOT IN
(SELECT convenio_id from solicituds where usuario_id=?”
That does not look like valid sql to me. Can you explain in words
what you are trying to achieve? I find this is often the best way of
working out how to code something.
Are you using Rails 2 or 3? The syntax that you’re responding to was
for Rails 3 (or Rails 2 + Arel).
A last I use
arreglo= Array.new
arreglo=solicituds.all(:select =>
“convenio_id”).map(&:convenio_id)
arreglo<<-1
Convenio.where([“id NOT IN (?)”,arreglo])
I’m not happy but works.
That’s not even good SQL. I think you want something like this SQL:
SELECT * FROM convenios c
LEFT JOIN solicituds s ON (s.convenio_id = c.id AND s.usuario_id =
:user_id)
WHERE s.id IS NULL
That gets everything in one query, and will be pretty easy to translate
into AR find arguments, so you won’t need find_by_sql here.
arreglo= Array.new
arreglo=solicituds.all(:select =>
“convenio_id”).map(&:convenio_id)
arreglo<<-1
Convenio.where([“id NOT IN (?)”,arreglo])
I’m not happy but works.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.