Greg H. wrote:
Is there any way of extending ActiveRecord to do something like:
<model_object>find_by_description_regex(/.find this.) ??
That is ActiveRecord support for find via use of regular expressions?
Perhaps a plugin? Or is there a reason this doesn’t exist?
ActiveRecord’s job is to turn a common Ruby DSL into a big SQL
Anything that common back-ends can’t do, ActiveRecord can’t do.
Google [mysql regular expressions] to see if someone has added that to
database back-end. Then use find_by_sql (and scrub any tainted data
prevent SQL injection attacks like this one: http://xkcd.com/327/ )
Until then, just use LIKE:
part = ‘A’
:conditions => [‘name LIKE ?’, part + ‘%’ ] )
The % is a wildcard for any length of string - like * in a fileglob