我有模型“秀”,其中has_many“表演”和表演有一定的“位置”。两个或更多的表演可能具有相同的位置。
我正在寻找一种方法来获得节目表演使用的所有地点,但只有一次(如果有三场具有地点X的演出,我只需要获得一次X)。
编辑:我现在的表单是:一个对象数组[[performance_id:1, location_id:1],[performance_id:2, location_id:1],[performance_id:3, location_id:2]]。如何获取包含1,2的数组?
发布于 2012-05-09 04:51:43
我在数组中添加了逗号:
[
[performance_id:1, location_id:1],
[performance_id:2, location_id:1],
[performance_id:3, location_id:2] ].flatten.map {|h| h[:location_id]}.uniq
=> [1, 2] 发布于 2012-05-09 03:56:34
我不确定这是否能帮到你
show.performances.collect(&:location).uniq发布于 2012-05-09 04:01:12
可能是这样的
Location.joins(:performances).where(:performances => { :show_id => 5 }).group("locations.id")https://stackoverflow.com/questions/10505515
复制相似问题