I have a JSON feed that I'm saving to the database, and within the array of data, there is a property that's an array:
{
"reports": [
{
"name1":"val1",
"name2":"val2",
"sub": [
{"x":9,"y":-8,"z":134},
{"x":10,"y":-7,"z":136}
]
}
]
}
The sub-array values will be saved into its own table so my question is: how can I easily insert the parent records, get the identity of the newly created record, and then save the sub-array records?
This is what I have so far, but as you could guess, the id of the sub-array values is nil.
rpts = metrics['reports']
saved_reports = Report.create rpts do |r|
if (r.sub != nil) then
SubReport.create r.sub do |a|
# How do I get the ID of the parent record?
a.report_id = r.id
end
end
end
Thanks for the help.
if saved_reports.saveblock and create it there?