2
我有表Many to Many Associations
两者之间:对于防爆用户&城市Rails的查询返回的用户属于任何城市及不属于任何城市
users
id name
1 Bob
2 Jon
3 Tom
4 Gary
5 Hary
cities
id name
1 London
2 New-york
3 Delhi
users_cities
id user_id city_id
1 1 2
2 2 1
3 3 1
4 3 2
5 4 3
我想两个SQL查询
查询其接受city_id数组并返回属于该城市的所有用户。 对于防爆时city_id:[1,2]然后结果应该是 O/P应是
id name
1 Bob
2 Jon
3 Tom
查询它接受city_id的阵列,并返回所有谁不属于这些城市的用户。 对于防爆时city_id:[1,2]然后结果应该是 O/P应是
id name
4 Gary
5 Hary
注: - 我使用
user.rb
has_and_belongs_to_many :cities
city.rb
has_and_belongs_to_many :users