Greg Hauptmann wrote:
> Hi,
> 
> 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 statement.

Anything that common back-ends can't do, ActiveRecord can't do.

Google [mysql regular expressions] to see if someone has added that to your 
database back-end. Then use find_by_sql (and scrub any tainted data yourself, 
to 
prevent SQL injection attacks like this one: http://xkcd.com/327/ )

Until then, just use LIKE:

   part = 'A'
   Foo.find_all_by_group_id(group_id,
           :conditions => ['name LIKE ?', part + '%' ] )

The % is a wildcard for any length of string - like * in a fileglob match.

-- 
   Phlip


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to