Skip to content

Commit c69fbaa

Browse files
author
graeme
committed
fix for GRAILS-2015
git-svn-id: https://svn.codehaus.org/grails/trunk@6475 1cfb16fd-6d17-0410-8ff1-b7e8e1e2867d
1 parent fc484c2 commit c69fbaa

File tree

9 files changed

+184
-111
lines changed

9 files changed

+184
-111
lines changed

src/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/ColumnConfig.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ColumnConfig {
3333
int precision = -1
3434
int scale = -1
3535
CacheConfig cache
36-
JoinTable joinTable
36+
JoinTable joinTable = new JoinTable()
3737

3838
String toString() {
3939
"column[name:$name, type:$type, index:$index, lazy:$lazy, unique:$unique, length:$length, precision:$precision, scale:$scale]"

src/groovy/org/codehaus/groovy/grails/orm/hibernate/cfg/HibernateMappingBuilder.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,9 @@ class HibernateMappingBuilder {
239239
}
240240
column.joinTable = join
241241
}
242+
else if(namedArgs.containsKey('joinTable') && namedArgs.joinTable == false) {
243+
column.joinTable = null
244+
}
242245

243246
mapping.columns[name] = column
244247
}

src/persistence/org/codehaus/groovy/grails/orm/hibernate/cfg/GrailsDomainBinder.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,10 @@ private static void bindCollectionWithJoinTable(GrailsDomainClassProperty proper
428428
}
429429

430430
private static boolean shouldCollectionBindWithJoinColumn(GrailsDomainClassProperty property) {
431-
return isUnidirectionalOneToMany(property);
431+
ColumnConfig cc = getColumnConfig(property);
432+
JoinTable jt = cc != null ? cc.getJoinTable() : new JoinTable();
433+
434+
return isUnidirectionalOneToMany(property) && jt!=null;
432435
}
433436

434437

@@ -818,7 +821,7 @@ private static void evaluateMapping(GrailsDomainClass domainClass) {
818821
* @return A Mapping object or null
819822
*/
820823
public static Mapping getMapping(String domainClassName) {
821-
return (Mapping)MAPPING_CACHE.get(domainClassName);
824+
return (Mapping) MAPPING_CACHE.get(domainClassName);
822825
}
823826

824827
/**
@@ -1703,8 +1706,13 @@ private static void bindColumn(GrailsDomainClassProperty grailsProp, Column colu
17031706

17041707
}
17051708
}
1706-
column.setNullable(true);
1707-
} else {
1709+
if(grailsProp.isManyToMany())
1710+
column.setNullable(false);
1711+
else {
1712+
1713+
column.setNullable(grailsProp.isOptional());
1714+
}
1715+
} else {
17081716
String columnName = getColumnNameForPropertyAndPath(grailsProp, path);
17091717
column.setName(columnName);
17101718
column.setNullable(grailsProp.isOptional());

test/groovy/org/codehaus/groovy/grails/orm/hibernate/BidirectionalMapOneToManyTests.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ class Stockpile
2727
String product
2828
Float quantity
2929
StockLocation stockLocation
30+
31+
static constraints = {
32+
stockLocation(nullable:true)
33+
}
3034
}
3135
'''
3236
}

test/groovy/org/codehaus/groovy/grails/orm/hibernate/CustomCascadeMappingTests.groovy

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ class CustomCascadeMappingOne {
1818
static hasMany = [foos:CustomCascadeMappingTwo, bars:CustomCascadeMappingTwo]
1919
2020
static mapping = {
21-
foos cascade:'none'
22-
bars cascade:'all'
21+
foos cascade:'none', joinTable:'foos'
22+
bars cascade:'all', joinTable:'bars'
2323
}
2424
}
2525

test/groovy/org/codehaus/groovy/grails/orm/hibernate/InheritanceWithAssociationsTests.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class Link {
2323
static belongsTo = Root
2424
2525
Root root
26+
27+
static constraints = {
28+
root(nullable:true)
29+
}
2630
}
2731
class LinkToA extends Link {
2832
Long id

test/groovy/org/codehaus/groovy/grails/orm/hibernate/MappedByColumn2Tests.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@ class Route {
4040
4141
Airport airport
4242
Airport destination
43+
44+
static constraints = {
45+
airport nullable:true
46+
}
4347
}
4448
'''
4549
)

test/groovy/org/codehaus/groovy/grails/orm/hibernate/SavePersistentMethodTests.groovy

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class SavePersistentMethodTests extends AbstractGrailsHibernateTests {
3535

3636
book.title = "Foo"
3737

38-
assert !book.save()
39-
assert !book.save(deepValidate:false)
38+
assert book.save()
4039

4140
def author = authorClass.newInstance()
4241
author.name = "Bar"
@@ -75,8 +74,8 @@ class SavePersistentMethodTests extends AbstractGrailsHibernateTests {
7574
assert !author.save()
7675
author.name = "Foo"
7776

78-
assert !author.save()
79-
assert !author.save(deepValidate:false)
77+
assert author.save()
78+
8079

8180
def address = addressClass.newInstance()
8281
author.address = address
@@ -109,7 +108,7 @@ class SaveBook {
109108
static belongsTo = SaveAuthor
110109
static constraints = {
111110
title(blank:false, size:1..255)
112-
author(nullable:false)
111+
author(nullable:true)
113112
}
114113
}
115114
class SaveAuthor {
@@ -120,7 +119,7 @@ class SaveAuthor {
120119
Set books = new HashSet()
121120
static hasMany = [books:SaveBook]
122121
static constraints = {
123-
address(nullable:false)
122+
address(nullable:true)
124123
name(size:1..255, blank:false)
125124
}
126125
}
@@ -131,7 +130,7 @@ class SaveAddress {
131130
String location
132131
static belongsTo = SaveAuthor
133132
static constraints = {
134-
author(nullable:false)
133+
author(nullable:true)
135134
location(blank:false)
136135
}
137136
}

0 commit comments

Comments
 (0)