I’ve programmatically built an array suitable for
ActiveRecord::Base.find()s
:conditions parameter. However, I’m also doing a find_by_sql on the same
model
and I want to generate the relevant WHERE clause.
Does Activerecord have an easy way to do this? I can’t see anything
immediately
in the docs
Thanks,
Gareth
Gareth A. wrote:
I’ve programmatically built an array suitable for
ActiveRecord::Base.find()s
:conditions parameter. However, I’m also doing a find_by_sql on the same
model
and I want to generate the relevant WHERE clause.
Does Activerecord have an easy way to do this? I can’t see anything
immediately
in the docs
Thanks,
Gareth
Look at sanitize_sql. It can accept an array with the first item being
an sql statement and subsequent items being the replacement values for
placeholders. Pass your conditions array to it, and a string will be
returned.