GORM: What is reference:true in Grails domain class mapping block?

落爺英雄遲暮 提交于 2019-12-05 13:08:19

It looks like reference controlls how documents are linked.

When true, the related documents are referenced by db-refs, if false, GORM inserts simple id, aka Manual references in mongo

This means that those properties will be stored on your Address record by reference. The id for Region and the id for Zone will exist on the record when you query the database instead of storing the entire object's mapping and any objects that its mapping may contain. Returning the Address object would look something like this:

{
  "id": "2413",
  "region": DBRef("region", "1234"),
  "zone": DBRef("zone", "4321")
}

For non-embedded associations by default GORM for MongoDB will map links between documents using MongoDB database references also known as DBRefs. If you prefer not to use DBRefs then you tell GORM to use direct links by using the reference:false mapping.

Gorm Mapping
Searchable Reference

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!