我在 Ruby 的“每个”语句中访问数据时遇到问题。我正在从 SQL 查询中获取数据,
mysql> select * from mantis_bug_relationship_table WHERE relationship_type = 2 AND destination_bug_id = 753;
+-----+---------------+--------------------+-------------------+
| id | source_bug_id | destination_bug_id | relationship_type |
+-----+---------------+--------------------+-------------------+
| 103 | 765 | 753 | 2 |
+-----+---------------+--------------------+-------------------+
然后我将每个结果添加到一个数组中,这样的关系类型为 2,
parent_map = {}
current = 1
# for each loop is here that populates parent_map
parent_map[current] = { issues_map[relation.destination_bug_id] => issues_map[relation.source_bug_id] }
current += 1
# for each loop is here that populates parent_map
然后我尝试从 parent_map 读取数据,如下所示:
parent_map.each do |child, parent|
pp parent_map
print "child: #{child}\n"
print "parent: #{parent}\n"
print "---------------------------------------\n"
STDOUT.flush
end
这输出如下:
{1=>{753=>765}}
child: 1
parent: 753765
输出应该是:
child: 753
parent: 765
我应该如何访问孩子和父母?