
エントリーの編集

エントリーの編集は全ユーザーに共通の機能です。
必ずガイドラインを一読の上ご利用ください。
has_many throughで重複したデータをdistinctしたい - Qiita
記事へのコメント0件
- 注目コメント
- 新着コメント
このエントリーにコメントしてみましょう。
注目コメント算出アルゴリズムの一部にLINEヤフー株式会社の「建設的コメント順位付けモデルAPI」を使用しています

- バナー広告なし
- ミュート機能あり
- ダークモード搭載
関連記事
has_many throughで重複したデータをdistinctしたい - Qiita
class User < ApplicationRecord has_many :lists end class List < ApplicationRecord belongs_to :use... class User < ApplicationRecord has_many :lists end class List < ApplicationRecord belongs_to :user belongs_to :product end class Product < ApplicationRecord has_many :lists end UserはListを複数持っていて、各ListはProductを参照していて... Userに関連するProduct全部持ってきたい... 解決方法 class User < ApplicationRecord has_many :lists # これだとListの数分重複するProductが返ってくる # has_many :products, through: :lists # distinctを差し込んでやる has_many :pro