7
4

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.

さようならこんにちは

Last updated at Posted at 2017-06-09

バージョン変更で過ぎ去ったあなたたちは、まるで僕のようだ。

uniqさよなら。distinctこんにちは。

uniq氏はdistinctのエイリアスでした。
uniq氏はrails5.1から、削除されます。
DEPRECATION WARNING: uniq is deprecated and will be removed from Rails 5.1 (use distinct instead)(uniqは廃止され、Rails 5.1から削除されます(代わりにdistinctを使用してください))」

[32] pry(main)> User.joins(:user_statuses)
.where(user_statuses: {service_id: [Settings.service_code,Settings.service_code_ferret]}).uniq
DEPRECATION WARNING: uniq is deprecated and will be removed from Rails 5.1 (use distinct instead) (called from <main> at (pry):28)
  User Load (0.6ms)  SELECT DISTINCT `mmember`.* FROM `mmember` INNER JOIN `user_statuses` ON `user_statuses`.`uid` = `mmember`.`uid` WHERE `user_statuses`.`service_id` IN (9, 4)
[31] pry(main)> User.joins(:user_statuses).where(user_statuses: {service_id: [Settings.service_code, Settings.service_code_ferret]}).distinct
  User Load (0.7ms)  SELECT DISTINCT `mmember`.* FROM `mmember` INNER JOIN `user_statuses` ON `user_statuses`.`uid` = `mmember`.`uid` WHERE `user_statuses`.`service_id` IN (9, 4)

uniq、またいつか。

first_or_createさよなら。find_or_create_byこんにちは。

first_or_createは削除されてないけど非推奨とされています。
非推奨にされた理由は読みづらさかららしいです。
廃止する可能性あるが、明確な廃止予定はないともありました。
「メソッドのfirst_or_createファミリは、このAPIのためにnodocされています。将来的に廃止される可能性がありますが、その実装はごくわずかであり、ユーザーには忌憚のない廃止予定の警告を送る価値はありません。」
http://blog.willnet.in/entry/2012/10/29/225845
https://github.com/rails/rails/blob/300d080ada31ac297264e6abba6ca16cd2db5925/activerecord/CHANGELOG.md

直近書いたfirst_or_create、確かに読みづらい。

# userに紐付いたuser_statusの中にSettings.service_codeと同じものがなければ、Settings.service_codeをセットして生成する。
user.user_statuses.where(service_id: Settings.service_code).first_or_create(service_id: Settings.service_code)

before_filterさよなら。before_actionこんにちは。

動作的には違いはなく、読みやすさのためだけの変更と公式が言っているのを見つけました。

Magizharasu ‏@magizh  2012年12月7日
 @rails is it just a change in name for readability ?
Ruby on Rails ‏@rails  2012年12月7日
 @magizh Yes.

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?