ActiveRecord find with expressions using fields

Suppose I have a table with two fields “a” and “b” – both integers. I
want to do:

select * from mytable where a + b > 18

I understand that I can pass :conditions a string but that has a few
limitations. If I want more conditions have to either do a with_scope
or figure out the proper thing to append to the string my hand. It also
has the limitation that I should not really say a or b, I should say
“mytable”.“a” and “mytable”.“b”. (At least, that is what pops out of
more find statements.) This particular example is for PostgreSQL and I
worry that there are other syntax forms for different DBs.

Is there a “best” way to do this? Has this type of thing already been


This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs