2014-02-07 1 views
0

Я использую Play Framework 2.2.1 и reactivemongo с плагином "org.reactivemongo" %% "play2-reactivemongo" % "0.10.2"ReactiveMongoDB плагин с рекурсивной структурой

Моя модель:

package models 

import system.db.Mongo 
import play.api.libs.concurrent.Execution.Implicits.defaultContext 
import play.api.libs.json.Json 
import scala.concurrent.Awaitable 
import scala.concurrent.duration._ 
import scala.concurrent.Await 

object Template { 
    import system.db.Mongo.JsonFormats._ 
    def findAll = Await.result(Mongo.templates.find(Json.obj()).cursor[Template].collect[List](), 3 seconds) 
} 

case class Template(name: String, marks: List[Mark], sections: List[Section]) 

case class Mark(name: String, description: String, index: Int, indexTree: String, dataType: String, rate: Int) 

case class Section(name: String, index: Int, indexTree: String, marks: List[Mark], section: List[Section]) 

Mongo.templates является JSONCollection: val templates: JSONCollection = db.collection[JSONCollection]("Templates")

JsonFormats:

object JsonFormats { 
    implicit val markFormat = Json.format[Mark] 
    implicit val sectionFormat = Json.format[Section] 
    implicit val templateFormat = Json.format[Template] 
} 

Когда я звоню Template.findAll с данными

{ 
    "name": "Caption", 
    "sections": [{ 
     "name": "Section name", 
     "index": 1, 
     "indexTree": "1", 
     "marks": [], 
     "sections": [] 
    }], 
    "marks": [] 
} 

есть исключение исполнения: [RuntimeException: JsError (List ((/ секции (0)/раздел, список (ValidationError (error.path.missing, WrappedArray())))))]

, но она работает с пустыми разделов: {"name": "Caption", "sections": [], "marks": []}

Является ли это драйвер поддерживает recoursive структуры?

ответ

1

Хорошо. Я решил как переименовани подал разделов в части:

case class Template(name: String, marks: List[Mark], sections: List[Section]) 

case class Mark(name: String, description: String, index: Int, indexTree: String, dataType: String, rate: Int) 

case class Section(name: String, index: Int, indexTree: String, marks: List[Mark], parts: List[Section]) 

Коллекция:

{ 
    "name": "Caption", 
    "sections": [{ 
     "name": "Section name", 
     "index": 1, 
     "indexTree": "1", 
     "marks": [], 
     "parts": [{ 
      ... 
      "parts": [...] 
     }, ...] 
    }], 
    "marks": [] 
}