Ruby의 "each"문에서 데이터에 액세스하는 데 문제가 있습니다. 나는 Ruby에서 배열의 데이터 액세스
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
가 그럼 난에서 데이터를 읽으려고,
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의 relationship_type이 때문에 같은 배열에 각 결과를 추가, SQL 쿼리에서 데이터를 잡는거야 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
는 어떻게 자녀와 부모에 액세스 할 수 하죠?
이미 자녀와 학부모에게 액세스하고 있습니다. 당신이 정확히 그걸로 무엇을하려고합니까? 기대하고있는 입력과 출력을 제공 할 수 있습니까? – Deepak
출력 내용을 내 질문에 편집했습니다. parent_map에 데이터를 추가 할 때 기본적으로 { '753'> = '765'}이 (가) 추가됩니다. – ethree