<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<oembed>
  <author_name>ohbarye</author_name>
  <author_url>https://blog.hatena.ne.jp/ohbarye/</author_url>
  <blog_title>valid,invalid</blog_title>
  <blog_url>https://ohbarye.hatenablog.jp/</blog_url>
  <categories>
    <anon>Ruby</anon>
    <anon>Ruby on Rails</anon>
    <anon>ActiveRecord</anon>
    <anon>ohbarye Advent Calendar 2020</anon>
  </categories>
  <description>has_many*1にblockを渡すとassociationにメソッドを追加することができる。 class User &lt; ActiveRecord::Base has_many :posts do def stats group(:status).count # このcontextで`self`は`ActiveRecord::Associations::CollectionProxy` # `proxy_association.owner`で`user.posts`の`user`にアクセスすることもできる end end end user.posts.stats # =&gt; {'draft'=…</description>
  <height>190</height>
  <html>&lt;iframe src=&quot;https://hatenablog-parts.com/embed?url=https%3A%2F%2Fohbarye.hatenablog.jp%2Fentry%2F2020%2F12%2F30%2Factive-record-association-extensions&quot; title=&quot;ActiveRecord Association extensionsでメソッドを追加する - valid,invalid&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>https://avatars3.githubusercontent.com/u/1811616</image_url>
  <provider_name>Hatena Blog</provider_name>
  <provider_url>https://hatena.blog</provider_url>
  <published>2020-12-30 20:34:25</published>
  <title>ActiveRecord Association extensionsでメソッドを追加する</title>
  <type>rich</type>
  <url>https://ohbarye.hatenablog.jp/entry/2020/12/30/active-record-association-extensions</url>
  <version>1.0</version>
  <width>100%</width>
</oembed>
