```ruby
joins(team_members: :team).where("team_members.current_member_team_flag": true, "team_members.active_flag", true)
  .where("teams.id", team.id)
```