2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Rails3のwhereのいろいろな使い方。

Last updated at Posted at 2012-12-26

*MySQLのLIKE検索

xxx.rb
User.where("name like?","%sato%")

*既存の別配列からの検索

xxx.rb
Topic.where("id in (?) or user_id in (?)", topic_id_list, user_id_list)

*null以外の検索

xxx.rb
Topic.where("user_id IS NOT NULL")

*日付を指定したの検索(3日前~5日前の場合)

xxx.rb
t1 = Time.now - 5.day
t2 = Time.now - 3.day
Topic.where(["created_at >= ? AND created_at <= ? " , t1 , t2])
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?