使用PlayFramework的JSON中的父子关系

使用PlayFramework的JSON中的父子关系,json,scala,playframework-2.0,slick,Json,Scala,Playframework 2.0,Slick,我需要给我的Angular JS应用程序一个JSON,它表示表的父子关系。 父组: +----+---------------+-------------+----------------+ | id | external_code | supplier_id | notes | +----+---------------+-------------+----------------+ | 19 | asdfas | 3 | sadfa

我需要给我的Angular JS应用程序一个JSON,它表示表的父子关系。 父组:

+----+---------------+-------------+----------------+
| id | external_code | supplier_id | notes          |
+----+---------------+-------------+----------------+
| 19 | asdfas        |           3 | sadfa          |
| 23 | 454           |           1 | groupa1        |
| 24 | sadfas221     |           2 | asfd           |
| 25 | dsafas        |           2 | NULL           |
| 21 | 4545          |           1 | asdfasf        |
+----+---------------+-------------+----------------+
儿童组项目:

+----------+---------+--------+
| group_id | item_id | status |
+----------+---------+--------+
|       19 |       1 |      0 |
|       19 |       2 |      0 |
|       19 |       3 |      0 |
|       25 |       2 |      0 |
+----------+---------+--------+
我想要的JSON应该如下所示:

[
{"groupId":"19",
"notes":"sadfa",
"extenalCode":"asdfas",
"supplierId":"2",
"itemCount":3
"items":[{"itemId": "1","status":"Created", "weight":23},
         {"itemId": "2","status":"Created", "weight":23}
         {"itemId": "3","status":"Created", "weight":23}
        ]

},

....

]
val items =
  GroupItems.join(Items).on(_.itemId === _.id).run // <- query fetching items with group_ids
            .groupBy(_._1.groupId).toMap
            .mapValues(_._2) // <- mapping Map values to only items

// render groups to json and add a field items with the items (I may be wrong about Play's json api names)
val json = Group.run.map(g => Json.toJson(g) ++ JsObject("items" -> Json.toJson(items(g.id))))

问题是如何使用MySQL和PlayFramework2.0Slick插入和绑定子项,并使用表示JSON语义的父项?

大致如下:

[
{"groupId":"19",
"notes":"sadfa",
"extenalCode":"asdfas",
"supplierId":"2",
"itemCount":3
"items":[{"itemId": "1","status":"Created", "weight":23},
         {"itemId": "2","status":"Created", "weight":23}
         {"itemId": "3","status":"Created", "weight":23}
        ]

},

....

]
val items =
  GroupItems.join(Items).on(_.itemId === _.id).run // <- query fetching items with group_ids
            .groupBy(_._1.groupId).toMap
            .mapValues(_._2) // <- mapping Map values to only items

// render groups to json and add a field items with the items (I may be wrong about Play's json api names)
val json = Group.run.map(g => Json.toJson(g) ++ JsObject("items" -> Json.toJson(items(g.id))))

将嵌套文档序列映射到多个文档序列中,每个嵌套级别对应一个文档序列,并添加父ID。然后使用insertAll插入每个序列的顶级项?@cvogt您能详细说明一下吗?我对scala和slick API真的很陌生。误读了你的问题,你不是在问数据库插入,对吧?