我有一组Active Record查询返回的记录。我需要以某种方式迭代这些以构建一个类似于哈希的哈希数组:
[
{ '15/01/2013': 3 },
{ '24/051/2012': 1 },
{ '08/07/2015': 22 }
]
返回的记录将以第一条记录为3条记录,第二条记录为1条记录,第三条记录为22条记录。我基本上需要一种方法将其转换为如上所述的简单哈希。
这是我的数据库输出的一个例子:
[
{
"item_id": 21728,
"id": 31731,
"notes": "sample",
"date": "2014-09-12",
"created_at": "2015-08-13T15:16:06.074Z",
"updated_at": "2015-08-13T15:16:06.074Z"
},
{
"item_id": 21728,
"id": 31732,
"notes": "sample",
"date": "2014-09-12",
"created_at": "2015-08-13T15:16:06.104Z",
"updated_at": "2015-08-13T15:16:06.104Z"
},
{
"item_id": 21728,
"id": 31733,
"notes": "sample",
"date": "2014-09-13",
"created_at": "2015-08-13T15:16:06.112Z",
"updated_at": "2015-08-13T15:16:06.112Z"
}
]