<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>shinkufencer</author_name>
  <author_url>https://blog.hatena.ne.jp/shinkufencer/</author_url>
  <blog_title>コード日進月歩</blog_title>
  <blog_url>https://shinkufencer.hateblo.jp/</blog_url>
  <categories>
    <anon>Ruby</anon>
    <anon>Rails</anon>
  </categories>
  <description>pluck(:id) を使っていたのでメモ程度に。 動作環境 $ bin/rails -v Rails 7.1.2 実例 Authorというモデルがあった場合、以下のように取得できる Author.ids # =&gt; [1, 2, 3] Author Ids (0.6ms) SELECT `authors`.`id` FROM `authors` # =&gt; Array こちらはModel側で主キーを別のものに指定している場合でもよしなに該当カラムを引き当ててくれるので、その点ではpluck(:id)よりも親切 実コード 実際のコードは以下の通り、再帰的なことをやっているのでわかりにくいが pri…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fshinkufencer.hateblo.jp%2Fentry%2F2025%2F09%2F13%2F153752&quot; title=&quot;RailsのActiveRecordで主キーの配列を取りたい場合はidsメソッドで取得できる - コード日進月歩&quot; class=&quot;embed-card embed-blogcard&quot; scrolling=&quot;no&quot; frameborder=&quot;0&quot; style=&quot;display: block; width: 100%; height: 190px; max-width: 500px; margin: 10px 0px;&quot;&gt;&lt;/iframe&gt;</html>
  <image_url></image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2025-09-13 15:37:52</published>
  <title>RailsのActiveRecordで主キーの配列を取りたい場合はidsメソッドで取得できる</title>
  <type>rich</type>
  <url>https://shinkufencer.hateblo.jp/entry/2025/09/13/153752</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
