1

I'm upgrading a Rails application from 4.2 to 5.x. We are using a firebird database and recently found a new adapter that can be used with Rails 5 as well.
After testing the application most of the stuff is working. But I have a problem with columns that are marked as a char field with the length of 1 - we are using this columns as boolean fields. 'F' means false and 'T' means true.

In our application we query the database for such fields like this:

model.where(inaktiv: [false, nil]

Which results in an sql statement like this:

select * from model where inaktiv in ('f', null)

The problem I have is the lowercase f. I searched in the active record gem where the mapping to string happens but I can't find the place. Where is this done?

Shimu
  • 1,137
  • 11
  • 25
  • that is one crazy code, `... in ( null )`. Albeit there is yet more insane option `...not in ( null )`. See https://stackoverflow.com/questions/6362112/in-clause-with-null-or-is-null – Arioch 'The Jul 22 '19 at 10:53

1 Answers1

0

Normally, you can create a query like so model.where("field IN (?)", ['F', 'T']) if you want to pass an array to look for, or just one value, like so: model.where("field = ?", 'T').

I do not recommend meddling with internals of ActiveRecord. Do it at your own risk.

Mihai C
  • 21
  • 2
  • this lib is broken (or we may say not polished yet) anyway if it manages to generate queries with `X in (null)` kinds of predicates. But that is FLOSS afterall, any FLOSS lib becomes part of *your* program that you just didn't write from scratch but took half-written. Does not relieve recipient from the second half of the work on your program, including on that now yours FLOSS lib. – Arioch 'The Jul 22 '19 at 11:19
  • Although it might not be suitable to do a ```in (null)``` but the firebird doesn't complaint about that and even gives back the right rows. – Shimu Jul 22 '19 at 11:33
  • @shimu what do you mean by "right rows" ? and of course it would not complain. It also would not complain about `delete from tablename -- where....` - a syntactically valid construct, albeit clearly a lapse turning deletion of a small rowset into uncontrollable wipe of the whole table. Here is the script: it does not return 3 but only 2! `Select count(*) from ( select 1 as id, 'aaa' as payload from rdb$database union all select 2, 'bbbbb' from rdb$database union all select null, 'cc' from rdb$database union all select 3, 'dddddd' from rdb$database ) d where d.id in (2,3,5, null)` – Arioch 'The Jul 22 '19 at 14:30