findメソッドで複数を指定

# テーブルの全てのレコードを表示
```rb
irb(main):001:0> User.all
  TRANSACTION (0.1ms)  BEGIN
  User Load (0.4ms)  SELECT `users`.* FROM `users`
=>
[#<User:0x000000010d10c698
  id: 79,
  name: "a",
  email: "hogehoge",
  password_digest: "[FILTERED]",
  user_image: "test.png",
  updated_at: Thu, 23 Jun 2022 05:42:39.000000000 UTC +00:00,
  created_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00>,
.
.
.
 #<User:0x000000010d2f4c30
  id: 110,
  name: "xxx",
  email: "xxx@xxx",
  password_digest: "[FILTERED]",
  user_image: nil,
  updated_at: Wed, 15 Jun 2022 05:52:57.000000000 UTC +00:00,
  created_at: Wed, 15 Jun 2022 05:52:57.000000000 UTC +00:00>]
```
```rb
irb(main):002:0> User.find(1,2,3)
  User Load (0.6ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IN (1, 2, 3)
/Users/**********/.rbenv/versions/3.1.1/lib/ruby/gems/3.1.0/gems/activerecord-7.0.2.3/lib/active_record/relation/finder_methods.rb:386:in `raise_record_not_found_exception!': Couldn't find all Users with 'id': (1, 2, 3) (found 0 results, but was looking for 3). (ActiveRecord::RecordNotFound)
```
# 複数のidを指定できる。
```rb
irb(main):003:0> User.find(100,101,102)
  User Load (0.6ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IN (100, 101, 102)
=>
[#<User:0x000000010dcb5c60
  id: 100,
  name: "tarou",
  email: "bbb@bbb",
  password_digest: nil,
  user_image: nil,
  updated_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00,
  created_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00>,
 #<User:0x000000010dcb5b98
  id: 101,
  name: "tarou",
  email: "ccc@ccc",
  password_digest: nil,
  user_image: nil,
  updated_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00,
  created_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00>,
 #<User:0x000000010dcb5ad0
  id: 102,
  name: "tarou",
  email: "aaa@aaa",
  password_digest: nil,
  user_image: nil,
  updated_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00,
  created_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00>]
irb(main):004:0> a = User.find(100,101,102)
  User Load (0.5ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IN (100, 101, 102)
=>
[#<User:0x000000010d76cab0
...
```
## idの値を文字列にしても可能
```rb
irb(main):007:0> a = User.find("100","101","102")
  User Load (0.6ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` IN (100, 101, 102)
=>
[#<User:0x000000010d886658
...
```
```rb
irb(main):008:0> a
=>
[#<User:0x000000010d886658
  id: 100,
  name: "tarou",
  email: "bbb@bbb",
  password_digest: nil,
  user_image: nil,
  updated_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00,
  created_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00>,
 #<User:0x000000010d886590
  id: 101,
  name: "tarou",
  email: "ccc@ccc",
  password_digest: nil,
  user_image: nil,
  updated_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00,
  created_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00>,
 #<User:0x000000010d8864c8
  id: 102,
  name: "tarou",
  email: "aaa@aaa",
  password_digest: nil,
  user_image: nil,
  updated_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00,
  created_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00>]
```
# クラスは配列
```rb
irb(main):005:0> a.class
=> Array
```
```rb
irb(main):006:0> a[0]
=>
#<User:0x000000010d76cab0
 id: 100,
 name: "tarou",
 email: "bbb@bbb",
 password_digest: nil,
 user_image: nil,
 updated_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00,
 created_at: Sat, 01 Jan 2000 00:00:00.000000000 UTC +00:00>
```
# 感想
```find```メソッドで複数指定ができることを知らなかった。
これから役に立ちそうだ。便利だ。

# 出典
https://qiita.com/nakayuu07/items/3d5e2f8784b6f18186f2