Given two models Player and Team how do I select all teams that two players specific players belong to?
Example Rails models and db table setup:
Rails models:
class Player < ActiveRecord::Base
  has_and_belongs_to_many :teams, uniq: true
end
class Team < ActiveRecord::Base
  has_and_belongs_to_many :players, uniq: true
end
SQL Tables
    teams         players            players_teams
+----------------------------------------------------+
| id | name |   | id | name |  | player_id | team_id |
+----+------+   +----+------+  +-----------+---------+
|  1 | Foo  |   |  1 | Jack |  |      1    |    1    |
|  2 | Bar  |   |  2 | Jill |  |      1    |    2    |
|    |      |   |    |      |  |      2    |    1    |
How do I select all teams that have both Jack and Jill on them? (In this case, just team Foo.)
 
     
     
     
    