GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / groovy / org / codehaus / groovy / grails / orm / hibernate / OneToManyWithJoinTableTests.groovy
blob67e98197a825a0eb43b41921a991594cea3d1138
1 /**
2 * @author Graeme Rocher
3 * @since 1.0
4 *
5 * Created: Oct 4, 2007
6 */
7 package org.codehaus.groovy.grails.orm.hibernate
8 class OneToManyWithJoinTableTests extends AbstractGrailsHibernateTests {
10 protected void onSetUp() {
11 gcl.parseClass('''
12 class Thing {
13 Long id
14 Long version
15 String name
18 class ThingGroup {
19 Long id
20 Long version
21 Set things
22 Set moreThings
23 static hasMany = [things: Thing, moreThings:Thing]
24 static mapping = {
25 columns {
26 things joinTable:true
27 moreThings joinTable:'more_things'
30 String name
32 ''')
36 void testOneToManyJoinTableMapping() {
37 def groupClass = ga.getDomainClass("ThingGroup")
38 def thingClass = ga.getDomainClass("Thing")
40 def g = groupClass.newInstance()
42 g.name = "Group 1"
43 def t1 = thingClass.newInstance()
44 t1.name = "Bob"
45 g.addToThings(t1)
46 g.save()
48 session.flush()
49 session.clear()
51 g = groupClass.clazz.get(1)
53 def t = thingClass.newInstance()
54 t.name = "Fred"
55 g.addToThings(t)
56 g.save()
58 session.flush()
59 session.clear()
61 g = groupClass.clazz.get(1)
62 assertEquals 2, g.things.size()