开发者

Rails3 - Is there a way to do NOTLIKE?

I previously asked a question regarding pulling specific items out of a database if they contained a specific word in their string, someone kindly offered the following which did just the job:

def SomeModel < ActiveRecord::Base
  scope :contains_city,
  lambda { |city| where("some_models.address LIKE ?","%"+city+"%" ) }
end

However, I have some instances where I would like to do the opposite, i.e. pull out all the items which do not have the specified word in their string. Is there a way to do a NOT LIKE function? I have pr开发者_Python百科evously seen people use '!=' for a NOT EQUALS, but have had no success along these lines for the LIKE function. Is there an equivalent or is it best to iterate through the database putting items in 2 separate databases based on whether they satisfy the LIKE condition?


You could try NOT LIKE in your query; MySQL supports this.

http://dev.mysql.com/doc/refman/5.0/en/string-comparison-functions.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜