[LRUG] Better idiom for this?

James Almond james at jamesalmond.com
Thu Feb 28 04:13:58 PST 2013


On 28 Feb 2013, at 11:56, Tom Stuart <tom at codon.com> wrote:

>>> Foo.where(['id NOT IN (?)', [Foo.first, Foo.find(2), 3, '4']]).to_sql
> => "SELECT \"foos\".* FROM \"foos\"  WHERE (id NOT IN (1,2,3,'4'))"
> 

One thing worth noting about this syntax is that with postgres (and possibly others)

Foo.where(['id NOT IN (?)', [])
=> SELECT "foo".* FROM "foo" WHERE (id NOT in (NULL))

which returns no rows at all. So something like Foo.excluding([]) wouldn't have the expected outcome in my opinion. I would expect it to be "Foo excluding nothing" when it actually returns "Foo excluding everything"

James

---
http://jamesalmond.com
@JamesAlmond




More information about the Chat mailing list