Many-to-Many Relationships

One of the concerns about bringing in a sponsor for a technical event is that the whole thing might turn into a commercial for a vendor. That becomes much less of a concern if there are multiple sponsors for an event. On the other hand, a single company might be interested in sponsoring more than one event. So, should a TekEvent have a collection of Sponsor instances, or should Sponsor have a collection of TekEvent instances? The short answer is both. The longer answer, which we’ll get to shortly, is neither.

The relationship between TekEvent and Sponsor is a many-to-many relationship. Grails supports many-to-many relationships implicitly by having each class include the other in its hasMany block. In this arrangement, ...

Get Grails 2: A Quick-Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.