GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / orm / hibernate / ManyToManyTests.groovy
blobc667a06a1b9e61f9e242ca199b8201a9e282fce8
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())
26 a.save(true)
28 a = null
30 assertEquals 1, bookClass.clazz.list().size()
32 def b = bookClass.clazz.get(1)
33 assert b
34 assert b.authors
36 a = authorClass.clazz.get(1)
37 assert a
38 assert a.books
40 assertEquals b, a.books.find { it.id == 1}
41 this.session.flush()
43 this.session.evict(a)
44 this.session.evict(b)
46 a = authorClass.clazz.get(1)
47 assert a
48 assert a.books
50 b = bookClass.clazz.get(1)
51 assert b
52 assert b.authors
55 void onSetUp() {
56 this.gcl.parseClass('''
57 class Book {
58 Long id
59 Long version
60 Set authors
61 def belongsTo = Author
62 def hasMany = [authors:Author]
64 class Author {
65 Long id
66 Long version
67 Set books
68 def hasMany = [books:Book]
70 class ApplicationDataSource {
71 boolean pooling = true
72 boolean logSql = 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"
77 String password = ""
79 '''
83 void onTearDown() {