开发者

YAML data format for mongodb collections and referenced entities

I want to load test data in my scala play application from data.yml file which is in YAML format.

My entities looks like:

@Entity("users")
User(@Required val uname: String, val isAdmin: Boolean = false)  {
  @Id var id: ObjectId = _

  @Reference val accounts = new ArrayList[Account]

}


@Entity("account")
class Account {

   @Id var id: ObjectId = _

  @Embedded val addresses = new ArrayList[Address] 
  @Reference val departments = new ArrayList[Department]  

  var description : String = _

}


class Address {
  street: String = _
  city: String = _

}

@Entity("department")
class Department {

 @Id var id: ObjectId = _

  principal: String = _ 

}

This is what almost a blank data.yml look like:

User(foo):
    uname: Foo
    accounts:

I want to开发者_Go百科 load one user with 2 accounts. One of the account has just one address and one department, the other account has 2 addresses and one department to keep things as simple as possible. So what the complete yml data looks to achieve this?


Why can't you just use lists with keys? Using the '- key' notation or '[key1, key2]'? Example:

Department(dep1):
   ..

Address(address1):
   ..

Address(address2):
   ..    

Account(account1):
   ..
   addresses:
       - address1
   departments:
       - dep1

Account(account2):
   ..
   addresses:
       - address1
       - address2
   departments:
       - dep1  

User(user1):
  ..
  accounts:
     - account1
     - account2

Check http://en.wikipedia.org/wiki/Yaml#Lists

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜