简体   繁体   English

Grails GORM中的单向M:M

[英]Unidirectional M:M in Grails GORM

Is it possible to have a Unidirectional M:M in Gorm? Gorm中可能有单向M:M吗?

eg I have a Person object and I have TravelDestionion object. 例如,我有一个Person对象,而我有TravelDestionion对象。

A person can have been to many travel destination and some of these travel destinations have of course had many people. 一个人可能去过很多旅行目的地,其中一些旅行目的地当然有很多人。 But, I never want to navigate from TravelDestination to Person. 但是,我从不想从TravelDestination导航到Person。

Any tips? 有小费吗?

You can technically just not access the other side, but Grails is too helpful in this regard. 从技术上讲,您不能访问另一端,但是Grails在这方面太有帮助了。 For example when you want to associate a new TravelDestination instance with a Person , you add it to the person's destinations collection (or whatever you named it). 例如,当您要将新的TravelDestination实例与Person关联时,可以将其添加TravelDestination人的destinations集合(或任何您命名的实例)中。 But to ensure that both sides are in sync with what the database will look like after calling save , Grails adds the Person to the TravelDestination 's persons collection. 但是,为了确保双方在调用save之后与数据库的外观保持同步,Grails将Person添加到TravelDestinationpersons集合中。

This can obviously be very expensive, eg with a User <-> Role relationship where 1,000,000 users have ROLE_USER, and one more gets that role, and that user becomes element #1,000,001 in the role's users collection, which gets loaded into memory by Hibernate to ensure uniqueness. 这显然可能非常昂贵,例如,通过用户<->角色关系,其中1,000,000个用户具有ROLE_USER,再有一个获得该角色,并且该用户成为角色的用户集合中的元素#1,000,001,由Hibernate加载到内存中以确保唯一性。

Check out this presentation where I discuss this and provide some performant options for reconfiguring the relationship without the potentially huge overhead of using collections to represent 1-many and many-many in GORM: http://www.infoq.com/presentations/GORM-Performance 在我讨论该内容的演示文稿中查看该演示文稿,并提供一些用于重新配置关系的高性能选项,而无需使用集合来表示GORM中的1个和许多个潜在的巨大开销: http : //www.infoq.com/presentations/GORM -性能

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM