Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(core): In memory database doesn't clear parent with removeFrom #1018

Open
wants to merge 1 commit into
base: 8.1.x
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package grails.gorm.tests

import grails.gorm.annotation.Entity
import spock.lang.Issue

class RemoveFromSpec extends GormDatastoreSpec {

@Issue("https://github.com/grails/grails-data-mapping/issues/998")
void "test removeFrom clears the back reference"() {
given:
new AuthorTest(name: "Joe").addToBooks(title: "Ready Player One").addToBooks(title: "Total Recall").save(flush: true, failOnError: true)
new BookTest(title: "Unrelated").save(flush: true, failOnError: true)
session.flush()
session.clear()
AuthorTest author = AuthorTest.first()
BookTest book = author.books.find { it.title == "Total Recall" }

expect:
author.books.size() == 2

when:
author.removeFromBooks(book)
author.save()
book.save()
session.flush()
session.clear()
author = AuthorTest.first()

then:
author.books.size() == 1
BookTest.count == 2
}

List getDomainClasses() {
[AuthorTest, BookTest]
}

}

@Entity
class AuthorTest {
String name

static hasMany = [books: BookTest]

static constraints = {
}
}

@Entity
class BookTest {
String title

static belongsTo = [author: AuthorTest]

static constraints = {
author nullable: true
}
}
Loading