GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / orm / hibernate / ManyToManyMappedByTests.groovy
blob3b5259075c4f0a10bf6aa3e15d7fbdf6bb4b14b0
1 /**
2 * @author Graeme Rocher
3 * @since 1.0
4 *
5 * Created: Dec 4, 2007
6 */
7 package org.codehaus.groovy.grails.orm.hibernate
9 import org.codehaus.groovy.grails.commons.test.AbstractGrailsMockTests
11 class ManyToManyMappedByTests extends AbstractGrailsHibernateTests {
13 protected void onSetUp() {
14 gcl.parseClass '''
15 class ManyToManyMappedByBook implements Serializable{
16 Long id
17 Long version
18 String title
20 ManyToManyMappedByAuthor creator
22 Set d
23 static hasMany = [d: ManyToManyMappedByAuthor]
24 static belongsTo = [ManyToManyMappedByAuthor]
27 class ManyToManyMappedByAuthor implements Serializable {
28 Long id
29 Long version
30 String email
31 Set books
32 static hasMany = [books: ManyToManyMappedByBook]
33 static mappedBy = [books:'d']
36 '''
39 void testDomain() {
40 def bookClass = ga.getDomainClass("ManyToManyMappedByBook")
41 def authorClass = ga.getDomainClass("ManyToManyMappedByAuthor")
43 assert bookClass.getPropertyByName("d").manyToMany
44 assert bookClass.getPropertyByName("d").bidirectional
45 assertEquals(authorClass.getPropertyByName("books"), bookClass.getPropertyByName("d").otherSide)
46 assert authorClass.getPropertyByName("books").manyToMany
47 assert authorClass.getPropertyByName("books").bidirectional
50 void testMapping() {
51 def bookClass = ga.getDomainClass("ManyToManyMappedByBook").clazz
52 def authorClass = ga.getDomainClass("ManyToManyMappedByAuthor").clazz
55 assert authorClass.newInstance(email:"foo@bar.com").save(flush:true)
57 def a = authorClass.get(1)
59 def book = bookClass.newInstance(creator:a, title:"The Stand")
60 a.addToBooks(book)
62 a.save(flush:true)
64 session.clear()
66 a = authorClass.get(1)
68 assertEquals 1, a.books.size()
71 book = bookClass.get(1)
73 assert book.creator
74 assertEquals 1, book.d.size()