File tree Expand file tree Collapse file tree 1 file changed +59
-0
lines changed
grails-datastore-gorm-test/src/test/groovy/grails/gorm/tests Expand file tree Collapse file tree 1 file changed +59
-0
lines changed Original file line number Diff line number Diff line change 1+ package grails.gorm.tests
2+
3+ import grails.gorm.annotation.Entity
4+ import spock.lang.Issue
5+
6+ class RemoveFromSpec extends GormDatastoreSpec {
7+
8+ @Issue (" https://github.com/grails/grails-data-mapping/issues/998" )
9+ void " test removeFrom clears the back reference" () {
10+ given :
11+ new AuthorTest (name : " Joe" ). addToBooks(title : " Ready Player One" ). addToBooks(title : " Total Recall" ). save(flush : true , failOnError : true )
12+ new BookTest (title : " Unrelated" ). save(flush : true , failOnError : true )
13+ session. flush()
14+ session. clear()
15+ AuthorTest author = AuthorTest . first()
16+ BookTest book = author. books. find { it. title == " Total Recall" }
17+
18+ expect :
19+ author. books. size() == 2
20+
21+ when :
22+ author. removeFromBooks(book)
23+ author. save()
24+ book. save()
25+ session. flush()
26+ session. clear()
27+ author = AuthorTest . first()
28+
29+ then :
30+ author. books. size() == 1
31+ BookTest . count == 2
32+ }
33+
34+ List getDomainClasses () {
35+ [AuthorTest , BookTest ]
36+ }
37+
38+ }
39+
40+ @Entity
41+ class AuthorTest {
42+ String name
43+
44+ static hasMany = [books : BookTest ]
45+
46+ static constraints = {
47+ }
48+ }
49+
50+ @Entity
51+ class BookTest {
52+ String title
53+
54+ static belongsTo = [author : AuthorTest ]
55+
56+ static constraints = {
57+ author nullable : true
58+ }
59+ }
You can’t perform that action at this time.
0 commit comments