2011-05-18 74 views
0

这里的的has_many关系的领域是什么,我现在在做:Rails的:如何缓存阵列中的

m = Merchant.find(1) 
ebay_item_id_array = [] 
active_items = m.active_items 
active_items.each { |item| 
    # Fill the array containing what items are already in the DB based on ebay item id 
    ebay_item_id_array.push(item.external_product_id) 
} 

这里的目标是这样,当我平eBay的API的最新产品,我可以检查我的数据库中是否已经有该ebay项目ID。因此,它会被跳过。问题是,当数据库变大时,上面的这个操作效率不高。我怎样才能将external_product_field缓存到一个数组中,我可以不用循环遍历所有活动记录?

回答