Advanced AREL or just Rails Query for has_many through search by association

#team.rb
has_many :players_teams
has_many :players, :through => :players_teams

#player.rb
has_many :players_teams
has_many :teams, :through => :players_teams

Given I have two star players named “Lisa” and “Bo”, how would would I search the Team Model to find all the teams that have both Lisa and Bo on them, without looping through. All the has_many through query examples assume I’m only looking for the teams by one association attribute. But I want to search by an array. [“Lisa”, “Bo”].

Leave a Comment