有没有办法从已经由id而不是数组索引的hash中的activerecord中拉出记录?这就是我目前正在做的事情:
results = {}
Table.select { |current| results[current.id] = current }我假设一定有一种方法可以做到这一点?
发布于 2012-12-06 06:42:54
Table.all.index_by { |t| t.id }或者:
Table.all.index_by(&:id)如果你对简洁感兴趣的话。
https://stackoverflow.com/questions/13733753
复制相似问题