Example:
:conditions => [" foo = ? AND bar = ? AND baz IN (?)",
single_value_1, single_value_2, array_of_values ]
To use this conditions array for my find_by_sql queries I do this.
conditions_array = [" foo = ? AND bar = ? AND baz IN (?)",
single_value_1, single_value_2, array_of_values ]
condition_string = ActiveRecord::Base.send(
"sanitize_sql_array", conditions_array)
Now I have nice condition_string I'm able to use in my custom queries. I'm not all that experienced with Ruby's handling of scope, so I'm using the send method to access this protected class method. Let me know if there's a nicer way to do this.
3 comments:
this solution looks very elegant to me!
This realy works, tanks
Useful. Thanks a bunch.
Post a Comment