0
0

More than 3 years have passed since last update.

whereメソッドで生SQLを書く時の注意

Posted at

文字列で生SQLを用意してwhereメソッドに渡す際
""を渡すと、少々極端な例だが下記のようになる。

sql = "id = 1"
User.where(sql)
# 発行されるSQL
# SELECT  `users`.* FROM `users` WHERE (id = 1)

sql = ""
User.where(sql)
# 発行されるSQL
# SELECT  `users`.* FROM `users`

エラーが出ず、不要なデータを取得するため注意。

0
0
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
0
0