camertron / scuttle-rb

A library for transforming raw SQL statements into ActiveRecord/Arel queries. Ruby wrapper and tests for scuttle-java.
86 stars 2 forks source link

NOT IN does not seem to be supported #5

Open jcaudle opened 8 years ago

jcaudle commented 8 years ago

If I provide scuttle with the following query:

SELECT * FROM a WHERE a.id NOT IN (SELECT b.a_id FROM b WHERE b.c_id = 1);

I am given the following Arel query:

A.select(Arel.star).where(
  B.select(B.arel_table[:a_id]).where(B.arel_table[:c_id].eq(1)).ast
)

If I call #to_sql on the query, I get something equivalent to this (I changed the Arel to use valid model names locally and have changed the table and column names here and removed the quotes to keep the same format as above):

SELECT * FROM a WHERE (SELECT b.a_id FROM b WHERE b.c_id = 1)

Is this because Arel doesn't support NOT IN conditions or is it a problem in scuttle-rb?

camertron commented 8 years ago

Hey @jcaudle I think this is because scuttle-rb (or actually scuttle-java) doesn't currently handle NOT IN clauses. I'll take a look. Thanks for the bug report!