Monday, August 21, 2006

LIKE as a condition to get records.

Here's a handy tip for Rails beginners: When you need to find records based on a condition that involves the use of LIKE '%value%' (it's going to be very slow since MySQL won't use an index for this query), try something like the following:

 @records = MyModel.find(:all, :conditions => ['col LIKE ? ', '%'+@term+'%'],:limit => 10)


At 10:19 PM, Blogger SHANMUKHA said...

Good..I got corre correct solution.


Post a Comment

<< Home

eXTReMe Tracker