1 package org
.codehaus
.groovy
.grails
.orm
.hibernate
;
3 import org
.codehaus
.groovy
.grails
.commons
.*
5 class ManyToManyTests
extends AbstractGrailsHibernateTests
{
7 void testManyToManyDomain() {
8 def authorDomain
= ga
.getDomainClass("Author")
9 def bookDomain
= ga
.getDomainClass("Book")
12 def books
= authorDomain?
.getPropertyByName("books")
13 def authors
= bookDomain?
.getPropertyByName("authors")
15 assert books?
.isManyToMany()
16 assert authors?
.isManyToMany()
17 assert !books?
.isOneToMany()
18 assert !authors?
.isOneToMany()
20 void testManyToManyMapping() {
21 def authorClass
= ga
.getDomainClass("Author")
22 def bookClass
= ga
.getDomainClass("Book")
23 def a
= authorClass
.newInstance()
25 a
.addToBooks(bookClass
.newInstance())
30 assertEquals
1, bookClass
.clazz
.list().size()
32 def b
= bookClass
.clazz
.get(1)
36 a
= authorClass
.clazz
.get(1)
40 assertEquals b
, a
.books
.find
{ it
.id
== 1}
46 a
= authorClass
.clazz
.get(1)
50 b
= bookClass
.clazz
.get(1)
56 this.gcl
.parseClass('''
61 def belongsTo = Author
62 def hasMany = [authors:Author]
68 def hasMany = [books:Book]
70 class ApplicationDataSource {
71 boolean pooling = true
73 String dbCreate = "create-drop" // one of 'create
', 'create
-drop
','update
'
74 String url = "jdbc:hsqldb:mem:testDB"
75 String driverClassName = "org.hsqldb.jdbcDriver"
76 String username = "sa"