使用子选择来约束结果:
User.joins(:pets).where( 'id IN (SELECt user_id FROM pets WHERe animal = ?) AND id IN (SELECt user_id FROM pets WHERe animal = ?)', 'cat', 'dog')

使用子选择来约束结果:
User.joins(:pets).where( 'id IN (SELECt user_id FROM pets WHERe animal = ?) AND id IN (SELECt user_id FROM pets WHERe animal = ?)', 'cat', 'dog')