1
0

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.

has_manyで、scopeを使って絞り込む

1
Posted at

merge で scope を指定すればOK。

user.rb
has_many :team_members
has_many(
  :pro_team_member,
  -> { merge(Team.pro) },
  through: :team_members,
  source: :team,
)

「何をもってproとするか」は、 Team 側が持つべき知識なので、 User 側で無闇に where(pro: true) みたいなコードを書くのは避けた方がよいです。

ドメイン知識が他のオブジェクトに流出している感じがするので。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?